UPS Tracking

G

Guest

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="testUser"
string UserPassword="testPW ";
string XmlRequest
string XmlResponse;

string hostname="wwwcie.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><TransactionReference>"
"<CustomerContext>Example 1</CustomerContext>"
"<XpciVersion>1.0001</XpciVersion>"
"</TransactionReference>"
"<RequestAction>Track</RequestAction>"
"<RequestOption>activity</RequestOption></Request>"
"<TrackingNumber>" + "1Z12345E0291980793" + "</TrackingNumber></TrackRequest>"

//WebProxy proxyObject = new WebProxy("http://wwwcie.ups.com:8080")

// Disable Proxy use when the host is local i.e. without periods
//proxyObject.BypassProxyOnLocal = true;

HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url)
myHttpWebRequest.Credentials = new NetworkCredential(UserName,UserPassword )
myHttpWebRequest.Method = "POST"
myHttpWebRequest.KeepAlive = false
//myHttpWebRequest.Connection = "/ups.app/xml/track";
myHttpWebRequest.UserAgent = "Test XML Request";

myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"

// Set the 'ContentLength' property of the WebRequest
myHttpWebRequest.ContentLength = XmlRequest.Length;

Stream SendStream=myHttpWebRequest.GetRequestStream();

ASCIIEncoding encodedData=new ASCIIEncoding()
byte[] byteArray=encodedData.GetBytes(XmlRequest)

SendStream.Write(byteArray,0,byteArray.Length)

HttpWebResponse WebResp = (HttpWebResponse) myHttpWebRequest.GetResponse()

// Now read the data from respons
//Get a readable stream from the server.
Stream RecvStream = WebResp.GetResponseStream()

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.Close()
WebResp.Close();
 
G

gary Vidal

The track is Case Sensitive Should be "Track"
HttpWebRequest said:
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="testUser";
string UserPassword="testPW ";
string XmlRequest;
string XmlResponse;

string hostname="wwwcie.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><TransactionReference>" +
"<CustomerContext>Example 1</CustomerContext>" +
"<XpciVersion>1.0001</XpciVersion>" +
"</TransactionReference>" +
"<RequestAction>Track</RequestAction>" +
"<RequestOption>activity</RequestOption></Request>" +
"<TrackingNumber>" + "1Z12345E0291980793" +
//WebProxy proxyObject = new WebProxy("http://wwwcie.ups.com:8080");

// Disable Proxy use when the host is local i.e. without periods.
//proxyObject.BypassProxyOnLocal = true;

HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);
myHttpWebRequest.Credentials = new
etworkCredential(UserName,UserPassword );
myHttpWebRequest.Method = "POST";
myHttpWebRequest.KeepAlive = false;
//myHttpWebRequest.Connection = "/ups.app/xml/track";
myHttpWebRequest.UserAgent = "Test XML Request";

myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myHttpWebRequest.ContentLength = XmlRequest.Length;

Stream SendStream=myHttpWebRequest.GetRequestStream();

ASCIIEncoding encodedData=new ASCIIEncoding();
byte[] byteArray=encodedData.GetBytes(XmlRequest);

SendStream.Write(byteArray,0,byteArray.Length);

HttpWebResponse WebResp = (HttpWebResponse) myHttpWebRequest.GetResponse();

// Now read the data from response
//Get a readable stream from the server.
Stream RecvStream = WebResp.GetResponseStream();

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.Close();
WebResp.Close();
 
G

gary Vidal

The track is Case Sensitive Should be "Track"

HttpWebRequest said:
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="testUser";
string UserPassword="testPW ";
string XmlRequest;
string XmlResponse;

string hostname="wwwcie.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><TransactionReference>" +
"<CustomerContext>Example 1</CustomerContext>" +
"<XpciVersion>1.0001</XpciVersion>" +
"</TransactionReference>" +
"<RequestAction>Track</RequestAction>" +
"<RequestOption>activity</RequestOption></Request>" +
"<TrackingNumber>" + "1Z12345E0291980793" +
//WebProxy proxyObject = new WebProxy("http://wwwcie.ups.com:8080");

// Disable Proxy use when the host is local i.e. without periods.
//proxyObject.BypassProxyOnLocal = true;

HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);
myHttpWebRequest.Credentials = new
etworkCredential(UserName,UserPassword );
myHttpWebRequest.Method = "POST";
myHttpWebRequest.KeepAlive = false;
//myHttpWebRequest.Connection = "/ups.app/xml/track";
myHttpWebRequest.UserAgent = "Test XML Request";

myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myHttpWebRequest.ContentLength = XmlRequest.Length;

Stream SendStream=myHttpWebRequest.GetRequestStream();

ASCIIEncoding encodedData=new ASCIIEncoding();
byte[] byteArray=encodedData.GetBytes(XmlRequest);

SendStream.Write(byteArray,0,byteArray.Length);

HttpWebResponse WebResp = (HttpWebResponse) myHttpWebRequest.GetResponse();

// Now read the data from response
//Get a readable stream from the server.
Stream RecvStream = WebResp.GetResponseStream();

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.Close();
WebResp.Close();
 
G

Guest

I tried like you suggested, I still can't get it working. By any chance you have an example to get tracking information. (Any language is fine)
 
G

gary Vidal

The URL is HTTPS://www.ups.com/ups.app/xml/Track
click thee above link and you will get a response from the server. Your
code looks fine. I would include the code for you but I have it wrapped up
in a large class file that accesses other carriers. If you really get stuck
I will send it to you.

HttpWebRequest said:
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="testUser";
string UserPassword="testPW ";
string XmlRequest;
string XmlResponse;

string hostname="wwwcie.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><TransactionReference>" +
"<CustomerContext>Example 1</CustomerContext>" +
"<XpciVersion>1.0001</XpciVersion>" +
"</TransactionReference>" +
"<RequestAction>Track</RequestAction>" +
"<RequestOption>activity</RequestOption></Request>" +
"<TrackingNumber>" + "1Z12345E0291980793" +
//WebProxy proxyObject = new WebProxy("http://wwwcie.ups.com:8080");

// Disable Proxy use when the host is local i.e. without periods.
//proxyObject.BypassProxyOnLocal = true;

HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);
myHttpWebRequest.Credentials = new
etworkCredential(UserName,UserPassword );
myHttpWebRequest.Method = "POST";
myHttpWebRequest.KeepAlive = false;
//myHttpWebRequest.Connection = "/ups.app/xml/track";
myHttpWebRequest.UserAgent = "Test XML Request";

myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myHttpWebRequest.ContentLength = XmlRequest.Length;

Stream SendStream=myHttpWebRequest.GetRequestStream();

ASCIIEncoding encodedData=new ASCIIEncoding();
byte[] byteArray=encodedData.GetBytes(XmlRequest);

SendStream.Write(byteArray,0,byteArray.Length);

HttpWebResponse WebResp = (HttpWebResponse) myHttpWebRequest.GetResponse();

// Now read the data from response
//Get a readable stream from the server.
Stream RecvStream = WebResp.GetResponseStream();

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.Close();
WebResp.Close();
 
G

Guest

I got it working. The magic is https, I am using http. It is working fine after I changed it to htpps

Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top