r/visualbasic • u/davef139 • 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
1
u/Medyu Aug 25 '20
I do it like this: