I am sending USPS a zipcode value and pounds to get a return back for cost. If I just past the uri and values into browser i get back an xml with my RATE. In code when the request posts to the server I get an error back on my request.getresponsse and it tells me i received nothing back.
Code below ( this code works until the oResponse
Dim strAPIUserId As String = "?API=RateV4&XML=<RateV4Request USERID=""425HOBKN7132"">"
Dim strRevision As String = "<Revision>2</Revision>"
Dim strOpenPackage As String = "<Package ID=""0"">"
Dim strService As String = "<Service>PARCEL</Service>"
Dim strZipOrigination As String = "<ZipOrigination>47119</ZipOrigination>"
Dim strZipDestinationStart As String = "<ZipDestination>"
Dim strZipDestinationZip As String = 47172 'strShipToZipCode
Dim strZipDestinationEnd As String = "</ZipDestination>"
Dim strPoundsStart As String = "<Pounds>"
Dim strPounds As String = 2 'intQty
Dim strPoundsEnd As String = "</Pounds>"
Dim strOunces As String = "<Ounces>0</Ounces>"
Dim strContainer As String = "<Container></Container>"
Dim strSize As String = "<Size>REGULAR</Size>"
Dim strMachinable As String = "<Machinable>true</Machinable>"
Dim strClosePackage As String = "</Package>"
Dim strClosing As String = "</RateV4Request>"
Dim strFullString As String = strAPIUserId & strRevision & strOpenPackage & strService & strZipOrigination & _
strZipDestinationStart & strZipDestinationZip & strZipDestinationEnd & _
strPoundsStart & strPounds & strPoundsEnd & strOunces & strContainer & strSize & _
strMachinable & strClosePackage & strClosing
Try
Dim uri As New Uri(" & strFullString)
Dim data As String = "field-keywords=ASP.NET 2.0"
Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
With request
.Method = WebRequestMethods.Http.Post
.ContentLength = data.Length
.ContentType = "application/x- End With
Dim writer As New StreamWriter(request.GetRequestStream)
With writer
.Write(data)
.Close()
End With
Dim oResponse As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(oResponse.GetResponseStream())
Dim strReturnData As String = reader.ReadToEnd()
oResponse.Close()
Dim Document As New System.Xml.XmlDocument
Document.LoadXml(strReturnData)
ShippingCost = Document.SelectSingleNode("Rate").InnerText
End
Thanks
Code below ( this code works until the oResponse
Dim strAPIUserId As String = "?API=RateV4&XML=<RateV4Request USERID=""425HOBKN7132"">"
Dim strRevision As String = "<Revision>2</Revision>"
Dim strOpenPackage As String = "<Package ID=""0"">"
Dim strService As String = "<Service>PARCEL</Service>"
Dim strZipOrigination As String = "<ZipOrigination>47119</ZipOrigination>"
Dim strZipDestinationStart As String = "<ZipDestination>"
Dim strZipDestinationZip As String = 47172 'strShipToZipCode
Dim strZipDestinationEnd As String = "</ZipDestination>"
Dim strPoundsStart As String = "<Pounds>"
Dim strPounds As String = 2 'intQty
Dim strPoundsEnd As String = "</Pounds>"
Dim strOunces As String = "<Ounces>0</Ounces>"
Dim strContainer As String = "<Container></Container>"
Dim strSize As String = "<Size>REGULAR</Size>"
Dim strMachinable As String = "<Machinable>true</Machinable>"
Dim strClosePackage As String = "</Package>"
Dim strClosing As String = "</RateV4Request>"
Dim strFullString As String = strAPIUserId & strRevision & strOpenPackage & strService & strZipOrigination & _
strZipDestinationStart & strZipDestinationZip & strZipDestinationEnd & _
strPoundsStart & strPounds & strPoundsEnd & strOunces & strContainer & strSize & _
strMachinable & strClosePackage & strClosing
Try
Dim uri As New Uri(" & strFullString)
Dim data As String = "field-keywords=ASP.NET 2.0"
Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
With request
.Method = WebRequestMethods.Http.Post
.ContentLength = data.Length
.ContentType = "application/x- End With
Dim writer As New StreamWriter(request.GetRequestStream)
With writer
.Write(data)
.Close()
End With
Dim oResponse As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(oResponse.GetResponseStream())
Dim strReturnData As String = reader.ReadToEnd()
oResponse.Close()
Dim Document As New System.Xml.XmlDocument
Document.LoadXml(strReturnData)
ShippingCost = Document.SelectSingleNode("Rate").InnerText
End
Thanks