r/visualbasic • • Aug 25 '20

VB.NET Web API POST

I recently fired up an old project. I did some searching and it appears my old methods are quite outdated. Can anyone point me in the direction on the updated?

Basically trying to send POST requests to an API and capture the response. I was using something basic like the below. From looking the webrequest/response has been replaced?

        Dim reqstring As String = ("http://production.shippingapis.com/ShippingAPI.dll?API=TrackV2&XML=<TrackRequest USERID='user'><TrackID ID='trkno'></TrackID></TrackRequest>")
        Dim TrackRequest As WebRequest = WebRequest.Create(reqstring)
        Dim responce As WebResponse = TrackRequest.GetResponse()
        Dim datastream As Stream = responce.GetResponseStream()
        Dim reader As New StreamReader(datastream)
        Dim responcefromserver As String = reader.ReadToEnd()
        Dim xmlout As XDocument = XDocument.Parse(responcefromserver)
7 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/andrewsmd87 Web Specialist Aug 25 '20

Are you doing a complete rebuild? Or just minor refactoring?

1

u/davef139 Aug 25 '20

Prob a larger overhaul as I plan to add quite a bit more API requests and such this covered a single, while I would like to access about 10. I will poke around the httpwebrequest classes.

1

u/andrewsmd87 Web Specialist Aug 25 '20

Not sure if it's feasible but if you're doing a large overhaul, I'd move to c#. The language is pretty translatable from VB and VB will at some point be not supported.

It would also allow you to move to .net core. Freeing up hosting restrictions to windows boxes

1

u/davef139 Aug 25 '20

Everything i have is winforms so the frontend is done. I just gotta work backend pulling my data in, my desire to change up everything isn't there either.

1

u/andrewsmd87 Web Specialist Aug 25 '20

Yea I get that, I just didn't know what "larger overhaul" encompassed.

The xml that you parse, is that in a class and objects, or are you using the old xml.childnode type stuff? That might be another area to look into. Xml/Json serialization is amazing