I am trying to get tracking information from UPS web site without much luck. I got this working in VB 60 without any problems by using WinInet functions
Here my test program. We need to get Tracking information from www.ups.com/ups.app/xml/track. When I tried to create the WebRequest with above ulr I get server not found. If I try www.ups.com, I do get connected but how I can post my message to ups.app/xml/track
I appricate your help in solving this problem
string url = "http://www.ups.com";
string UserName="testU ser"
string UserPassword="t estPW ";
string XmlRequest
string XmlResponse;
string hostname="wwwci e.ups.com"
string prefix = "ups.app/xml"
string service ="track"
//URL url = new URL(protocol + "://" + hostname + "/" + prefix + "/" + service)
url = "http://" + hostname + "/" + prefix + "/" + service
XmlRequest =
"<?xml version=1.0?>"
" <TrackRequest xml:lang=en-US>"
"<Request><Tran sactionReferenc e>"
"<CustomerConte xt>Example 1</CustomerContext >"
"<XpciVersion>1 .0001</XpciVersion>"
"</TransactionRefe rence>"
"<RequestAction >Track</RequestAction>"
"<RequestOption >activity</RequestOption></Request>"
"<TrackingNumbe r>" + "1Z12345E029198 0793" + "</TrackingNumber> </TrackRequest>"
//WebProxy proxyObject = new WebProxy("http://wwwcie.ups.com: 8080")
// Disable Proxy use when the host is local i.e. without periods
//proxyObject.Byp assProxyOnLocal = true;
HttpWebRequest myHttpWebReques t = (HttpWebRequest ) WebRequest.Crea te(url)
myHttpWebReques t.Credentials = new NetworkCredenti al(UserName,Use rPassword )
myHttpWebReques t.Method = "POST"
myHttpWebReques t.KeepAlive = false
//myHttpWebReques t.Connection = "/ups.app/xml/track";
myHttpWebReques t.UserAgent = "Test XML Request";
myHttpWebReques t.ContentType = "applicatio n/x-www-form-urlencoded"
// Set the 'ContentLength' property of the WebRequest
myHttpWebReques t.ContentLength = XmlRequest.Leng th;
Stream SendStream=myHt tpWebRequest.Ge tRequestStream( );
ASCIIEncoding encodedData=new ASCIIEncoding()
byte[] byteArray=encod edData.GetBytes (XmlRequest)
SendStream.Writ e(byteArray,0,b yteArray.Length )
HttpWebResponse WebResp = (HttpWebRespons e) myHttpWebReques t.GetResponse()
// Now read the data from respons
//Get a readable stream from the server.
Stream RecvStream = WebResp.GetResp onseStream()
byte[] readBuff = new byte[256]
int bytesread
XmlResponse = ""
//Read from the stream and write any data to the console
bytesread = RecvStream.Read ( readBuff, 0, 256)
while( bytesread > 0 )
{
bytesread = RecvStream.Read ( readBuff, 0, 256)
XmlResponse = XmlResponse + readBuff
MessageBox.Show (XmlResponse)
RecvStream.Clos e()
WebResp.Close() ;