WebRequest method usage

G

Guest

I am working on a WebRequest accessing the US Postal Service WebTools test API.
This service uses a DLL file (ShippingAPITest.dll) with a query string which
includes XML.
The web service accepts the query string with no url encoding.
I must pass the <> characters as they are in the query string.
If these characters are url encoded the service rejects the request.


This API Url is
http://testing.shippingapis.com/ShippingAPITest.dll

It takes a query string as follows:

?API=RateV2&XML=<RateV2Request USERID="userid" PASSWORD="password"> <Package
ID="0"> <Service>PRIORITY</Service> <ZipOrigination>10022</ZipOrigination>
<ZipDestination>20008</ZipDestination> <Pounds>10</Pounds> <Ounces>5</Ounces>
<Container>Flat Rate Box</Container>
<Size>REGULAR</Size></Package></RateV2Request>


I can use this url and query string from the location bar of the web
browser and it will return the correct xml response. If this query string is
encoded, the DLL will return an error. The USPS DLL is not decoding an
encoded query string. The USPS is not up to date with the latest Xml
technology and uses the DLL to retreive the query string and process the
request.
I am very limited to what I can do with this service provider.

Can someone tell me how to use the WebRequest method without encoding the
request?

Thanks for your help.
 
B

bruce barker

try building the uri yourself with escape turned off

string url =
"http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=<RateV2R
equest USERID="userid" PASSWORD="password"> <Package ID="0">
<Service>PRIORITY</Service>
<ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination>
<Pounds>10</Pounds> <Ounces>5</Ounces>
<Container>Flat Rate Box</Container>
<Size>REGULAR</Size></Package></RateV2Request>";

Uri uri = new Uri(url,false);
WebRequest wr = WebRequest.Create(uri);

-- bruce (sqlwork.com)


| I am working on a WebRequest accessing the US Postal Service WebTools test
API.
| This service uses a DLL file (ShippingAPITest.dll) with a query string
which
| includes XML.
| The web service accepts the query string with no url encoding.
| I must pass the <> characters as they are in the query string.
| If these characters are url encoded the service rejects the request.
|
|
| This API Url is
| http://testing.shippingapis.com/ShippingAPITest.dll
|
| It takes a query string as follows:
|
| ?API=RateV2&XML=<RateV2Request USERID="userid" PASSWORD="password">
<Package
| ID="0"> <Service>PRIORITY</Service> <ZipOrigination>10022</ZipOrigination>
| <ZipDestination>20008</ZipDestination> <Pounds>10</Pounds>
<Ounces>5</Ounces>
| <Container>Flat Rate Box</Container>
| <Size>REGULAR</Size></Package></RateV2Request>
|
|
| I can use this url and query string from the location bar of the web
| browser and it will return the correct xml response. If this query string
is
| encoded, the DLL will return an error. The USPS DLL is not decoding an
| encoded query string. The USPS is not up to date with the latest Xml
| technology and uses the DLL to retreive the query string and process the
| request.
| I am very limited to what I can do with this service provider.
|
| Can someone tell me how to use the WebRequest method without encoding the
| request?
|
| Thanks for your help.
 
G

Guest

Bruce,
Thanks very much for your help. Your info was excellent.
The Uri dontencode parameter set to true does create a uri without encoding.

I also have a problem with the xml attitudes. The attitudes require the
value of the attitube to be between double quotes. When building the xml
string with the String or StringBuilder you must use the \ character on
the inner double quotes.
This puts a \ in the string as follows:

<RateV2Request USERID=\"userid\" PASSWORD=\"password\">
<Package ID=\"0\">

This causes an error. Need help with a way to build this xml string without
the \ character. I am going to try building an XmlDocument and pass the
document stream to the Uri constructor.

If you can help, please reply.
 
P

Precept

ThyRock,

I have been working on trying to pass the userid and password without
the escape character for a solid week. I came across this article and
saw that you encountered the same problem. How did you fix it? I
currently use an XmlTextWriter, Memory Stream and XmlDocument objects
to form the xml parameter. I am trying to complete an ecommerce site
for a friends business. He uses dhl, ups, and usps for his shipping. I
have 2 of 3 done, but the usps is becoming pesky problem. Do you have
any suggestions? Any help would be appreciated

Precept
 
G

Guest

Precept,
I am also working on a Shipping component, and would be interested in any
problems I may encounter on the UPS service. I have got the USPS service
working and am now going to start on the UPS service. I have included the
USPS code for you.

replace userid with your USPS UserID
replace userpassword with your USPS Password

string userID = "userid";
string password = "userpassword";
string service = "PRIORITY";
string zipOrigination = "10022";
string zipDestination = "20008";
string pounds = "10";
string ounces = "5";
string container = "Flat Rate Box";
string size = "REGULAR";

StringBuilder stringBuilder = new StringBuilder(
"http://testing.shippingapis.com/ShippingAPITest.dll" );

stringBuilder.Append( "?API=RateV2&XML=" );
stringBuilder.Append( "<RateV2Request USERID=\"" );
stringBuilder.Append( userID + "\" " );
stringBuilder.Append( "PASSWORD=\"" );
stringBuilder.Append( password + "\">" );
stringBuilder.Append( "<Package ID=\"0\">" );
stringBuilder.Append( "<Service>" + service + "</Service>" );
stringBuilder.Append( "<ZipOrigination>" + zipOrigination +
"</ZipOrigination>" );
stringBuilder.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
stringBuilder.Append( "<Pounds>" + pounds + "</Pounds>" );
stringBuilder.Append( "<Ounces>" + ounces + "</Ounces>" );
stringBuilder.Append( "<Container>" + container + "</Container>" );
stringBuilder.Append( "<Size>" + size + "</Size>" );
stringBuilder.Append( "</Package></RateV2Request>" );

WebRequest webRequest = WebRequest.Create( stringBuilder.ToString() );

try
{
WebResponse webResponse = webRequest.GetResponse();
Stream webResponseStream = webResponse.GetResponseStream();

// txtHTML is a TextArea control to display the raw response for
development
// purposes.
// You would unpack the xml document here and return the needed values

Byte[] read = new Byte[512];
int bytes = webResponseStream.Read( read, 0, 512 );

txtHTML.InnerHtml = "";
while ( bytes > 0 )
{
// Note:
// The following assumes that the response uses UTF-8 as encoding.
// If the content is sent in a ANSI codepage like 932 use something like
this:
// Encoding encode = System.Text.Encoding.GetEncoding("shift-jis");
Encoding encode = System.Text.Encoding.GetEncoding( "utf-8" );
txtHTML.InnerHtml = txtHTML.InnerHtml + encode.GetString(read, 0, bytes);
bytes = webResponseStream.Read( read, 0, 512 );

// End of development code.
}
}
catch(Exception)
{
txtHTML.InnerHtml = "Error retrieving page";
}

The above request returns the following response:

<?xml version="1.0"?>
<RateV2Response><Package
ID="0"><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat
Rate
Box</Container><Size>REGULAR</Size><Zone>3</Zone><Postage><MailService>Priority
Mail Flat Rate Box (11.25" x 8.75" x
6")</MailService><Rate>7.70</Rate></Postage><Postage><MailService>Priority
Mail Flat Rate Box (14" x 12" x
3.5")</MailService><Rate>7.70</Rate></Postage></Package></RateV2Response>
 
P

Precept

ThyRock,

Thx for the quick response. I see that you are not using as Uri object
and are passing in a StringBuilder...hmm I will have to try that
hopefully the XML format will be maintained and not encoded. I have the
UPS shipping code done. I don't know if you want to build the component
yourself for the experience or whatever..., but I have the code and can
give it to you if you want to save coding time. BTW I also have the DHL
component done if you want that one too, or I can give you the info you
need if you want to code that component yourself..just let me know

Thx Precept

Precept,
I am also working on a Shipping component, and would be interested in any
problems I may encounter on the UPS service. I have got the USPS service
working and am now going to start on the UPS service. I have included the
USPS code for you.

replace userid with your USPS UserID
replace userpassword with your USPS Password

string userID = "userid";
string password = "userpassword";
string service = "PRIORITY";
string zipOrigination = "10022";
string zipDestination = "20008";
string pounds = "10";
string ounces = "5";
string container = "Flat Rate Box";
string size = "REGULAR";

StringBuilder stringBuilder = new StringBuilder(
"http://testing.shippingapis.com/ShippingAPITest.dll" );

stringBuilder.Append( "?API=RateV2&XML=" );
stringBuilder.Append( "<RateV2Request USERID=\"" );
stringBuilder.Append( userID + "\" " );
stringBuilder.Append( "PASSWORD=\"" );
stringBuilder.Append( password + "\">" );
stringBuilder.Append( "<Package ID=\"0\">" );
stringBuilder.Append( "<Service>" + service + "</Service>" );
stringBuilder.Append( "<ZipOrigination>" + zipOrigination +
"</ZipOrigination>" );
stringBuilder.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
stringBuilder.Append( "<Pounds>" + pounds + "</Pounds>" );
stringBuilder.Append( "<Ounces>" + ounces + "</Ounces>" );
stringBuilder.Append( "<Container>" + container + "</Container>" );
stringBuilder.Append( "<Size>" + size + "</Size>" );
stringBuilder.Append( "</Package></RateV2Request>" );

WebRequest webRequest = WebRequest.Create( stringBuilder.ToString() );

try
{
WebResponse webResponse = webRequest.GetResponse();
Stream webResponseStream = webResponse.GetResponseStream();

// txtHTML is a TextArea control to display the raw response for
development
// purposes.
// You would unpack the xml document here and return the needed values

Byte[] read = new Byte[512];
int bytes = webResponseStream.Read( read, 0, 512 );

txtHTML.InnerHtml = "";
while ( bytes > 0 )
{
// Note:
// The following assumes that the response uses UTF-8 as encoding.
// If the content is sent in a ANSI codepage like 932 use something like
this:
// Encoding encode = System.Text.Encoding.GetEncoding("shift-jis");
Encoding encode = System.Text.Encoding.GetEncoding( "utf-8" );
txtHTML.InnerHtml = txtHTML.InnerHtml + encode.GetString(read, 0, bytes);
bytes = webResponseStream.Read( read, 0, 512 );

// End of development code.
}
}
catch(Exception)
{
txtHTML.InnerHtml = "Error retrieving page";
}

The above request returns the following response:

<?xml version="1.0"?>
<RateV2Response><Package
ID="0"> said:
Box said:
Mail Flat Rate Box (11.25" x 8.75" x
 
G

Guest

Precept,
I tried the URI object and it will return a uri without encoding if you pass
the dontencode parameter set to true.
I tried the StringBuilder approach and it worked so I have move on to the
next step.
There are many ways of reaching the same end and I would like very much to
look at
your approach to using the UPS DHL services.
Thanks,

Precept said:
ThyRock,

Thx for the quick response. I see that you are not using as Uri object
and are passing in a StringBuilder...hmm I will have to try that
hopefully the XML format will be maintained and not encoded. I have the
UPS shipping code done. I don't know if you want to build the component
yourself for the experience or whatever..., but I have the code and can
give it to you if you want to save coding time. BTW I also have the DHL
component done if you want that one too, or I can give you the info you
need if you want to code that component yourself..just let me know

Thx Precept

Precept,
I am also working on a Shipping component, and would be interested in any
problems I may encounter on the UPS service. I have got the USPS service
working and am now going to start on the UPS service. I have included the
USPS code for you.

replace userid with your USPS UserID
replace userpassword with your USPS Password

string userID = "userid";
string password = "userpassword";
string service = "PRIORITY";
string zipOrigination = "10022";
string zipDestination = "20008";
string pounds = "10";
string ounces = "5";
string container = "Flat Rate Box";
string size = "REGULAR";

StringBuilder stringBuilder = new StringBuilder(
"http://testing.shippingapis.com/ShippingAPITest.dll" );

stringBuilder.Append( "?API=RateV2&XML=" );
stringBuilder.Append( "<RateV2Request USERID=\"" );
stringBuilder.Append( userID + "\" " );
stringBuilder.Append( "PASSWORD=\"" );
stringBuilder.Append( password + "\">" );
stringBuilder.Append( "<Package ID=\"0\">" );
stringBuilder.Append( "<Service>" + service + "</Service>" );
stringBuilder.Append( "<ZipOrigination>" + zipOrigination +
"</ZipOrigination>" );
stringBuilder.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
stringBuilder.Append( "<Pounds>" + pounds + "</Pounds>" );
stringBuilder.Append( "<Ounces>" + ounces + "</Ounces>" );
stringBuilder.Append( "<Container>" + container + "</Container>" );
stringBuilder.Append( "<Size>" + size + "</Size>" );
stringBuilder.Append( "</Package></RateV2Request>" );

WebRequest webRequest = WebRequest.Create( stringBuilder.ToString() );

try
{
WebResponse webResponse = webRequest.GetResponse();
Stream webResponseStream = webResponse.GetResponseStream();

// txtHTML is a TextArea control to display the raw response for
development
// purposes.
// You would unpack the xml document here and return the needed values

Byte[] read = new Byte[512];
int bytes = webResponseStream.Read( read, 0, 512 );

txtHTML.InnerHtml = "";
while ( bytes > 0 )
{
// Note:
// The following assumes that the response uses UTF-8 as encoding.
// If the content is sent in a ANSI codepage like 932 use something like
this:
// Encoding encode = System.Text.Encoding.GetEncoding("shift-jis");
Encoding encode = System.Text.Encoding.GetEncoding( "utf-8" );
txtHTML.InnerHtml = txtHTML.InnerHtml + encode.GetString(read, 0, bytes);
bytes = webResponseStream.Read( read, 0, 512 );

// End of development code.
}
}
catch(Exception)
{
txtHTML.InnerHtml = "Error retrieving page";
}

The above request returns the following response:

<?xml version="1.0"?>
<RateV2Response><Package
ID="0"> said:
Box said:
Mail Flat Rate Box (11.25" x 8.75" x
6") said:
Mail Flat Rate Box (14" x 12" x
 
P

Precept

ThyRock,

Sorry to get back to you so late...was at work late and just finished
with the family thing dinner etc.....
I used the HTML developers guide because it was easy to develop....here
is the code along with my USPS code
I am using webservices for all three DHL, UPS, and USPS...damn fedex
can't get there stinkin docs! I changed my USPS code to a stringbuilder
like your example..code looks a little more cluttered using
XmlTextWriter, MemoryStream, and XmlDocument...
I have some merchant components coded, we can exhange some code if you
would like...The ups xml service is pretty straight forward maybe I
will code for the xml service this weekend, if you want to wait till
then..otherwise this one works

Cheers,

Precept

-----UPS
[WebMethod]
public decimal GetPrice(string svcCode, string rateChart,string
shipperZIP,string receiverZIP,
string receiverCountry,string pkgWeight,string
isResidential, string isCOD,
string isSatPickup,string isSatDelivery, string pkgType)
{
decimal shippingRate = 0;
WebRequest myWebReq;
WebResponse myWebResp;
StreamReader myStream;
string URLRequest;
string responseLine;

URLRequest =
BuildRequest(svcCode,rateChart,shipperZIP,receiverZIP,"US",pkgWeight,isResidential,isCOD,isSatPickup,isSatDelivery,pkgType);


myWebReq = WebRequest.Create(URLRequest);
myWebResp = myWebReq.GetResponse();

myStream = new StreamReader(myWebResp.GetResponseStream(),
System.Text.Encoding.ASCII);
try
{
responseLine = myStream.ReadLine();

while(responseLine != null)
{
responseLine = myStream.ReadLine();

if (responseLine.Length > 0)
{
if (responseLine.ToLower().IndexOf("upsonline", 0,
responseLine.Length) > -1)
{
string[] arr;
char[] perct = new char[1];
perct[0] = '%';
arr = responseLine.Split(perct);
if (arr[3].Substring(0,11).ToLower() == "0000success")
shippingRate = Convert.ToDecimal(arr[12]);

responseLine = null;
}
}

}


}
catch(Exception e)
{
throw new AppException("Error occured trying to calculate UPS
shiping", e);
}

return shippingRate;
}


private string BuildRequest(string svcCode, string rateChart, string
shipperZIP, string receiverZIP,
string receiverCountry, string pkgWeight, string isResidential,
string isCOD,
string isSatPickup, string isSatDelivery, string pkgType)
{

System.Text.StringBuilder ups = new System.Text.StringBuilder();

ups.Append("http://www.ups.com/using/services/rave/qcost_dss.cgi?");
ups.Append("AppVersion=1.2&AcceptUPSLicenseAgreement=YES&");
ups.Append("ResponseType=application/x-ups-rss&ActionCode=3&");
ups.Append("ServiceLevelCode=" + svcCode + "&RateChart=" + rateChart
+ "&");
ups.Append("ShipperPostalCode=" + shipperZIP +
"&ConsigneePostalCode=" + receiverZIP + "&");
ups.Append("ConsigneeCountry=" + receiverCountry +
"&PackageActualWeight=" + pkgWeight + "&");
ups.Append("ResidentialInd=" + isResidential + "&CODInd=" + isCOD +
"&SatDelivInd=" + isSatDelivery);
ups.Append("&SatPickupInd=" + isSatPickup + "&PackagingType=" +
pkgType);

return
ups.ToString();
}


----USPS
[WebMethod]
public decimal GetPrice(string userID, string password, string
zipOrigin, string zipDestination,
string pounds, string ounces, string container, string size, string
service)
{
WebRequest myWebReq;
WebResponse myWebResp;
StreamReader myStream;
string UrlRequest;
decimal shippingRate = 0;

UrlRequest = BuildRequest(userID, password, zipOrigin,
zipDestination, pounds, ounces, container, size, service);

myWebReq = WebRequest.Create(UrlRequest);

try
{
myWebResp = myWebReq.GetResponse();

myStream = new StreamReader(myWebResp.GetResponseStream(),
System.Text.Encoding.ASCII);

XmlTextReader xmlReader = new XmlTextReader(myStream);

System.Text.StringBuilder response = new
System.Text.StringBuilder();

while (xmlReader.Read())
{
if (xmlReader.MoveToContent() == XmlNodeType.Element &&
xmlReader.Name.ToUpper() == "RATE")
{
shippingRate = Convert.ToDecimal(xmlReader.ReadString());
}
}

return shippingRate;
}
catch(Exception e)
{
throw new AppException("Error occured trying to calculate USPS
shiping", e);
}
}

private string BuildRequest(string userID, string password, string
zipOrigin,
string zipDestination, string pounds, string ounces, string
container,
string size, string service)
{
System.Text.StringBuilder usps = new System.Text.StringBuilder();
usps.Append("http://testing.shippingapis.com/ShippingAPITest.dll");
usps.Append( "?API=RateV2&XML=" );
usps.Append( "<RateV2Request USERID=\"" );
usps.Append( userID + "\" " );
usps.Append( "PASSWORD=\"" );
usps.Append( password + "\">" );
usps.Append( "<Package ID=\"0\">" );
usps.Append( "<Service>" + service + "</Service>" );
usps.Append( "<ZipOrigination>" + zipOrigin + "</ZipOrigination>" );

usps.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
usps.Append( "<Pounds>" + pounds + "</Pounds>" );
usps.Append( "<Ounces>" + ounces + "</Ounces>" );
usps.Append( "<Container>" + container + "</Container>" );
usps.Append( "<Size>" + size + "</Size>" );
usps.Append( "</Package></RateV2Request>" );

return usps.ToString();
}
Precept,
I tried the URI object and it will return a uri without encoding if you pass
the dontencode parameter set to true.
I tried the StringBuilder approach and it worked so I have move on to the
next step.
There are many ways of reaching the same end and I would like very much to
look at
your approach to using the UPS DHL services.
Thanks,

Precept said:
ThyRock,

Thx for the quick response. I see that you are not using as Uri object
and are passing in a StringBuilder...hmm I will have to try that
hopefully the XML format will be maintained and not encoded. I have the
UPS shipping code done. I don't know if you want to build the component
yourself for the experience or whatever..., but I have the code and can
give it to you if you want to save coding time. BTW I also have the DHL
component done if you want that one too, or I can give you the info you
need if you want to code that component yourself..just let me know

Thx Precept

Precept,
I am also working on a Shipping component, and would be
interested in
any
problems I may encounter on the UPS service. I have got the USPS service
working and am now going to start on the UPS service. I have included the
USPS code for you.

replace userid with your USPS UserID
replace userpassword with your USPS Password

string userID = "userid";
string password = "userpassword";
string service = "PRIORITY";
string zipOrigination = "10022";
string zipDestination = "20008";
string pounds = "10";
string ounces = "5";
string container = "Flat Rate Box";
string size = "REGULAR";

StringBuilder stringBuilder = new StringBuilder(
"http://testing.shippingapis.com/ShippingAPITest.dll" );

stringBuilder.Append( "?API=RateV2&XML=" );
stringBuilder.Append( "<RateV2Request USERID=\"" );
stringBuilder.Append( userID + "\" " );
stringBuilder.Append( "PASSWORD=\"" );
stringBuilder.Append( password + "\">" );
stringBuilder.Append( "<Package ID=\"0\">" );
stringBuilder.Append( "<Service>" + service + "</Service>" );
stringBuilder.Append( "<ZipOrigination>" + zipOrigination +
"</ZipOrigination>" );
stringBuilder.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
stringBuilder.Append( "<Pounds>" + pounds + "</Pounds>" );
stringBuilder.Append( "<Ounces>" + ounces + "</Ounces>" );
stringBuilder.Append( "<Container>" + container + "</Container>" );
stringBuilder.Append( "<Size>" + size + "</Size>" );
stringBuilder.Append( "</Package></RateV2Request>" );

WebRequest webRequest = WebRequest.Create(
stringBuilder.ToString()
);
try
{
WebResponse webResponse = webRequest.GetResponse();
Stream webResponseStream = webResponse.GetResponseStream();

// txtHTML is a TextArea control to display the raw response for
development
// purposes.
// You would unpack the xml document here and return the needed values

Byte[] read = new Byte[512];
int bytes = webResponseStream.Read( read, 0, 512 );

txtHTML.InnerHtml = "";
while ( bytes > 0 )
{
// Note:
// The following assumes that the response uses UTF-8 as encoding.
// If the content is sent in a ANSI codepage like 932 use something like
this:
// Encoding encode = System.Text.Encoding.GetEncoding("shift-jis");
Encoding encode = System.Text.Encoding.GetEncoding( "utf-8" );
txtHTML.InnerHtml = txtHTML.InnerHtml + encode.GetString(read,
0,
bytes);
bytes = webResponseStream.Read( read, 0, 512 );

// End of development code.
}
}
catch(Exception)
{
txtHTML.InnerHtml = "Error retrieving page";
}

The above request returns the following response:

<?xml version="1.0"?>
<RateV2Response><Package
Box said:
Mail Flat Rate Box (11.25" x 8.75" x
6") said:
Mail Flat Rate Box (14" x 12" x
3.5") said:
:

ThyRock,

I have been working on trying to pass the userid and password without
the escape character for a solid week. I came across this
article
and
saw that you encountered the same problem. How did you fix it? I
currently use an XmlTextWriter, Memory Stream and XmlDocument objects
to form the xml parameter. I am trying to complete an ecommerce site
for a friends business. He uses dhl, ups, and usps for his shipping. I
have 2 of 3 done, but the usps is becoming pesky problem. Do
you
have
any suggestions? Any help would be appreciated

Precept

ThyRock wrote:
Bruce,
Again, thanks very much for your help, I have work out this problem.


:

I am working on a WebRequest accessing the US Postal Service
WebTools test API.
This service uses a DLL file (ShippingAPITest.dll) with a query
string which
includes XML.
The web service accepts the query string with no url encoding.
I must pass the <> characters as they are in the query string.
If these characters are url encoded the service rejects the
request.


This API Url is
http://testing.shippingapis.com/ShippingAPITest.dll

It takes a query string as follows:

?API=RateV2&XML=<RateV2Request USERID="userid" PASSWORD="password">
<Package
ID="0"> <Service>PRIORITY</Service>
<ZipOrigination>10022</ZipOrigination>
<ZipDestination>20008</ZipDestination> <Pounds>10</Pounds>
<Ounces>5</Ounces>
<Container>Flat Rate Box</Container>
<Size>REGULAR</Size></Package></RateV2Request>


I can use this url and query string from the location bar
of
the
web
browser and it will return the correct xml response. If
this
query
string is
encoded, the DLL will return an error. The USPS DLL is not
decoding an
encoded query string. The USPS is not up to date with the latest
Xml
technology and uses the DLL to retreive the query string and
process the
request.
I am very limited to what I can do with this service provider.

Can someone tell me how to use the WebRequest method without
encoding the
request?

Thanks for your help.
 
P

Precept

ThyRock,

I have the xml version just about done I am authenticating and get a
response but its saying I don't have a well formed document..funny i am
using the example they provided...I should have it figured out by
tonight

Precept
ThyRock,

Sorry to get back to you so late...was at work late and just finished
with the family thing dinner etc.....
I used the HTML developers guide because it was easy to develop....here
is the code along with my USPS code
I am using webservices for all three DHL, UPS, and USPS...damn fedex
can't get there stinkin docs! I changed my USPS code to a stringbuilder
like your example..code looks a little more cluttered using
XmlTextWriter, MemoryStream, and XmlDocument...
I have some merchant components coded, we can exhange some code if you
would like...The ups xml service is pretty straight forward maybe I
will code for the xml service this weekend, if you want to wait till
then..otherwise this one works

Cheers,

Precept

-----UPS
[WebMethod]
public decimal GetPrice(string svcCode, string rateChart,string
shipperZIP,string receiverZIP,
string receiverCountry,string pkgWeight,string
isResidential, string isCOD,
string isSatPickup,string isSatDelivery, string pkgType)
{
decimal shippingRate = 0;
WebRequest myWebReq;
WebResponse myWebResp;
StreamReader myStream;
string URLRequest;
string responseLine;

URLRequest =
BuildRequest(svcCode,rateChart,shipperZIP,receiverZIP,"US",pkgWeight,isResidential,isCOD,isSatPickup,isSatDelivery,pkgType);


myWebReq = WebRequest.Create(URLRequest);
myWebResp = myWebReq.GetResponse();

myStream = new StreamReader(myWebResp.GetResponseStream(),
System.Text.Encoding.ASCII);
try
{
responseLine = myStream.ReadLine();

while(responseLine != null)
{
responseLine = myStream.ReadLine();

if (responseLine.Length > 0)
{
if (responseLine.ToLower().IndexOf("upsonline", 0,
responseLine.Length) > -1)
{
string[] arr;
char[] perct = new char[1];
perct[0] = '%';
arr = responseLine.Split(perct);
if (arr[3].Substring(0,11).ToLower() == "0000success")
shippingRate = Convert.ToDecimal(arr[12]);

responseLine = null;
}
}

}


}
catch(Exception e)
{
throw new AppException("Error occured trying to calculate UPS
shiping", e);
}

return shippingRate;
}


private string BuildRequest(string svcCode, string rateChart, string
shipperZIP, string receiverZIP,
string receiverCountry, string pkgWeight, string isResidential,
string isCOD,
string isSatPickup, string isSatDelivery, string pkgType)
{

System.Text.StringBuilder ups = new System.Text.StringBuilder();

ups.Append("http://www.ups.com/using/services/rave/qcost_dss.cgi?");
ups.Append("AppVersion=1.2&AcceptUPSLicenseAgreement=YES&");
ups.Append("ResponseType=application/x-ups-rss&ActionCode=3&");
ups.Append("ServiceLevelCode=" + svcCode + "&RateChart=" + rateChart
+ "&");
ups.Append("ShipperPostalCode=" + shipperZIP +
"&ConsigneePostalCode=" + receiverZIP + "&");
ups.Append("ConsigneeCountry=" + receiverCountry +
"&PackageActualWeight=" + pkgWeight + "&");
ups.Append("ResidentialInd=" + isResidential + "&CODInd=" + isCOD +
"&SatDelivInd=" + isSatDelivery);
ups.Append("&SatPickupInd=" + isSatPickup + "&PackagingType=" +
pkgType);

return
ups.ToString();
}


----USPS
[WebMethod]
public decimal GetPrice(string userID, string password, string
zipOrigin, string zipDestination,
string pounds, string ounces, string container, string size, string
service)
{
WebRequest myWebReq;
WebResponse myWebResp;
StreamReader myStream;
string UrlRequest;
decimal shippingRate = 0;

UrlRequest = BuildRequest(userID, password, zipOrigin,
zipDestination, pounds, ounces, container, size, service);

myWebReq = WebRequest.Create(UrlRequest);

try
{
myWebResp = myWebReq.GetResponse();

myStream = new StreamReader(myWebResp.GetResponseStream(),
System.Text.Encoding.ASCII);

XmlTextReader xmlReader = new XmlTextReader(myStream);

System.Text.StringBuilder response = new
System.Text.StringBuilder();

while (xmlReader.Read())
{
if (xmlReader.MoveToContent() == XmlNodeType.Element &&
xmlReader.Name.ToUpper() == "RATE")
{
shippingRate = Convert.ToDecimal(xmlReader.ReadString());
}
}

return shippingRate;
}
catch(Exception e)
{
throw new AppException("Error occured trying to calculate USPS
shiping", e);
}
}

private string BuildRequest(string userID, string password, string
zipOrigin,
string zipDestination, string pounds, string ounces, string
container,
string size, string service)
{
System.Text.StringBuilder usps = new System.Text.StringBuilder();
usps.Append("http://testing.shippingapis.com/ShippingAPITest.dll");
usps.Append( "?API=RateV2&XML=" );
usps.Append( "<RateV2Request USERID=\"" );
usps.Append( userID + "\" " );
usps.Append( "PASSWORD=\"" );
usps.Append( password + "\">" );
usps.Append( "<Package ID=\"0\">" );
usps.Append( "<Service>" + service + "</Service>" );
usps.Append( "<ZipOrigination>" + zipOrigin + "</ZipOrigination>" );

usps.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
usps.Append( "<Pounds>" + pounds + "</Pounds>" );
usps.Append( "<Ounces>" + ounces + "</Ounces>" );
usps.Append( "<Container>" + container + "</Container>" );
usps.Append( "<Size>" + size + "</Size>" );
usps.Append( "</Package></RateV2Request>" );

return usps.ToString();
}
Precept,
I tried the URI object and it will return a uri without encoding if you pass
the dontencode parameter set to true.
I tried the StringBuilder approach and it worked so I have move on
to
the
next step.
There are many ways of reaching the same end and I would like very much to
look at
your approach to using the UPS DHL services.
Thanks,
have
and
the
info
);
stringBuilder.Append( "<Size>" + size + "</Size>" );
stringBuilder.Append( "</Package></RateV2Request>" );

WebRequest webRequest = WebRequest.Create( stringBuilder.ToString()
);

try
{
WebResponse webResponse = webRequest.GetResponse();
Stream webResponseStream = webResponse.GetResponseStream();

// txtHTML is a TextArea control to display the raw response for
development
// purposes.
// You would unpack the xml document here and return the needed
values

Byte[] read = new Byte[512];
int bytes = webResponseStream.Read( read, 0, 512 );

txtHTML.InnerHtml = "";
while ( bytes > 0 )
{
// Note:
// The following assumes that the response uses UTF-8 as encoding.
// If the content is sent in a ANSI codepage like 932 use
something like
this:
// Encoding encode =
System.Text.Encoding.GetEncoding("shift-jis");
Encoding encode = System.Text.Encoding.GetEncoding( "utf-8" );
txtHTML.InnerHtml = txtHTML.InnerHtml +
encode.GetString(read,
it?
 
P

Precept

ThyRock,

I have it working....let me know if you need help with the code....
email me (e-mail address removed)

Precept
ThyRock,

I have the xml version just about done I am authenticating and get a
response but its saying I don't have a well formed document..funny i am
using the example they provided...I should have it figured out by
tonight

Precept
ThyRock,

Sorry to get back to you so late...was at work late and just finished
with the family thing dinner etc.....
I used the HTML developers guide because it was easy to develop....here
is the code along with my USPS code
I am using webservices for all three DHL, UPS, and USPS...damn fedex
can't get there stinkin docs! I changed my USPS code to a stringbuilder
like your example..code looks a little more cluttered using
XmlTextWriter, MemoryStream, and XmlDocument...
I have some merchant components coded, we can exhange some code if you
would like...The ups xml service is pretty straight forward maybe I
will code for the xml service this weekend, if you want to wait till
then..otherwise this one works

Cheers,

Precept

-----UPS
[WebMethod]
public decimal GetPrice(string svcCode, string rateChart,string
shipperZIP,string receiverZIP,
string receiverCountry,string pkgWeight,string
isResidential, string isCOD,
string isSatPickup,string isSatDelivery, string pkgType)
{
decimal shippingRate = 0;
WebRequest myWebReq;
WebResponse myWebResp;
StreamReader myStream;
string URLRequest;
string responseLine;

URLRequest =
BuildRequest(svcCode,rateChart,shipperZIP,receiverZIP,"US",pkgWeight,isResidential,isCOD,isSatPickup,isSatDelivery,pkgType);
myWebReq = WebRequest.Create(URLRequest);
myWebResp = myWebReq.GetResponse();

myStream = new StreamReader(myWebResp.GetResponseStream(),
System.Text.Encoding.ASCII);
try
{
responseLine = myStream.ReadLine();

while(responseLine != null)
{
responseLine = myStream.ReadLine();

if (responseLine.Length > 0)
{
if (responseLine.ToLower().IndexOf("upsonline", 0,
responseLine.Length) > -1)
{
string[] arr;
char[] perct = new char[1];
perct[0] = '%';
arr = responseLine.Split(perct);
if (arr[3].Substring(0,11).ToLower() == "0000success")
shippingRate = Convert.ToDecimal(arr[12]);

responseLine = null;
}
}

}


}
catch(Exception e)
{
throw new AppException("Error occured trying to calculate UPS
shiping", e);
}

return shippingRate;
}


private string BuildRequest(string svcCode, string rateChart, string
shipperZIP, string receiverZIP,
string receiverCountry, string pkgWeight, string isResidential,
string isCOD,
string isSatPickup, string isSatDelivery, string pkgType)
{

System.Text.StringBuilder ups = new System.Text.StringBuilder();
ups.Append("http://www.ups.com/using/services/rave/qcost_dss.cgi?");
ups.Append("AppVersion=1.2&AcceptUPSLicenseAgreement=YES&");
ups.Append("ResponseType=application/x-ups-rss&ActionCode=3&");
ups.Append("ServiceLevelCode=" + svcCode + "&RateChart=" + rateChart
+ "&");
ups.Append("ShipperPostalCode=" + shipperZIP +
"&ConsigneePostalCode=" + receiverZIP + "&");
ups.Append("ConsigneeCountry=" + receiverCountry +
"&PackageActualWeight=" + pkgWeight + "&");
ups.Append("ResidentialInd=" + isResidential + "&CODInd=" +
isCOD
+
"&SatDelivInd=" + isSatDelivery);
ups.Append("&SatPickupInd=" + isSatPickup + "&PackagingType=" +
pkgType);

return
ups.ToString();
}


----USPS
[WebMethod]
public decimal GetPrice(string userID, string password, string
zipOrigin, string zipDestination,
string pounds, string ounces, string container, string size, string
service)
{
WebRequest myWebReq;
WebResponse myWebResp;
StreamReader myStream;
string UrlRequest;
decimal shippingRate = 0;

UrlRequest = BuildRequest(userID, password, zipOrigin,
zipDestination, pounds, ounces, container, size, service);

myWebReq = WebRequest.Create(UrlRequest);

try
{
myWebResp = myWebReq.GetResponse();

myStream = new StreamReader(myWebResp.GetResponseStream(),
System.Text.Encoding.ASCII);

XmlTextReader xmlReader = new XmlTextReader(myStream);

System.Text.StringBuilder response = new
System.Text.StringBuilder();

while (xmlReader.Read())
{
if (xmlReader.MoveToContent() == XmlNodeType.Element &&
xmlReader.Name.ToUpper() == "RATE")
{
shippingRate = Convert.ToDecimal(xmlReader.ReadString());
}
}

return shippingRate;
}
catch(Exception e)
{
throw new AppException("Error occured trying to calculate USPS
shiping", e);
}
}

private string BuildRequest(string userID, string password, string
zipOrigin,
string zipDestination, string pounds, string ounces, string
container,
string size, string service)
{
System.Text.StringBuilder usps = new System.Text.StringBuilder();
usps.Append("http://testing.shippingapis.com/ShippingAPITest.dll");
usps.Append( "?API=RateV2&XML=" );
usps.Append( "<RateV2Request USERID=\"" );
usps.Append( userID + "\" " );
usps.Append( "PASSWORD=\"" );
usps.Append( password + "\">" );
usps.Append( "<Package ID=\"0\">" );
usps.Append( "<Service>" + service + "</Service>" );
usps.Append( "<ZipOrigination>" + zipOrigin +
);

usps.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
usps.Append( "<Pounds>" + pounds + "</Pounds>" );
usps.Append( "<Ounces>" + ounces + "</Ounces>" );
usps.Append( "<Container>" + container + "</Container>" );
usps.Append( "<Size>" + size + "</Size>" );
usps.Append( "</Package></RateV2Request>" );

return usps.ToString();
}
if
you pass
on
to
the
next step.
There are many ways of reaching the same end and I would like
very
much to
look at
your approach to using the UPS DHL services.
Thanks,

:

ThyRock,

Thx for the quick response. I see that you are not using as Uri object
and are passing in a StringBuilder...hmm I will have to try that
hopefully the XML format will be maintained and not encoded. I
have
the
UPS shipping code done. I don't know if you want to build the component
yourself for the experience or whatever..., but I have the code
and
can
give it to you if you want to save coding time. BTW I also have
the
DHL
component done if you want that one too, or I can give you the
info
you
need if you want to code that component yourself..just let me know

Thx Precept


ThyRock wrote:
Precept,
I am also working on a Shipping component, and would be interested in
any
problems I may encounter on the UPS service. I have got the USPS
service
working and am now going to start on the UPS service. I have
included the
USPS code for you.

replace userid with your USPS UserID
replace userpassword with your USPS Password

string userID = "userid";
string password = "userpassword";
string service = "PRIORITY";
string zipOrigination = "10022";
string zipDestination = "20008";
string pounds = "10";
string ounces = "5";
string container = "Flat Rate Box";
string size = "REGULAR";

StringBuilder stringBuilder = new StringBuilder(
"http://testing.shippingapis.com/ShippingAPITest.dll" );

stringBuilder.Append( "?API=RateV2&XML=" );
stringBuilder.Append( "<RateV2Request USERID=\"" );
stringBuilder.Append( userID + "\" " );
stringBuilder.Append( "PASSWORD=\"" );
stringBuilder.Append( password + "\">" );
stringBuilder.Append( "<Package ID=\"0\">" );
stringBuilder.Append( "<Service>" + service + "</Service>" );
stringBuilder.Append( "<ZipOrigination>" + zipOrigination +
"</ZipOrigination>" );
stringBuilder.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
stringBuilder.Append( "<Pounds>" + pounds + "</Pounds>" );
stringBuilder.Append( "<Ounces>" + ounces + "</Ounces>" );
stringBuilder.Append( "<Container>" + container +
);
stringBuilder.Append( "<Size>" + size + "</Size>" );
stringBuilder.Append( "</Package></RateV2Request>" );

WebRequest webRequest = WebRequest.Create( stringBuilder.ToString()
);

try
{
WebResponse webResponse = webRequest.GetResponse();
Stream webResponseStream = webResponse.GetResponseStream();

// txtHTML is a TextArea control to display the raw
response
for
development
// purposes.
// You would unpack the xml document here and return the needed
values

Byte[] read = new Byte[512];
int bytes = webResponseStream.Read( read, 0, 512 );

txtHTML.InnerHtml = "";
while ( bytes > 0 )
{
// Note:
// The following assumes that the response uses UTF-8 as encoding.
// If the content is sent in a ANSI codepage like 932 use
something like
this:
// Encoding encode =
System.Text.Encoding.GetEncoding("shift-jis");
Encoding encode = System.Text.Encoding.GetEncoding(
"utf-8"
); encode.GetString(read,



it? Do
you a
query bar
of If
this string
and
 
G

Guest

Hi,
I was wondering if you would be kind enough to share some info on your DHL
sample.

Thanks

Precept said:
ThyRock,

I have it working....let me know if you need help with the code....
email me (e-mail address removed)

Precept
ThyRock,

I have the xml version just about done I am authenticating and get a
response but its saying I don't have a well formed document..funny i am
using the example they provided...I should have it figured out by
tonight

Precept
ThyRock,

Sorry to get back to you so late...was at work late and just finished
with the family thing dinner etc.....
I used the HTML developers guide because it was easy to develop....here
is the code along with my USPS code
I am using webservices for all three DHL, UPS, and USPS...damn fedex
can't get there stinkin docs! I changed my USPS code to a stringbuilder
like your example..code looks a little more cluttered using
XmlTextWriter, MemoryStream, and XmlDocument...
I have some merchant components coded, we can exhange some code if you
would like...The ups xml service is pretty straight forward maybe I
will code for the xml service this weekend, if you want to wait till
then..otherwise this one works

Cheers,

Precept

-----UPS
[WebMethod]
public decimal GetPrice(string svcCode, string rateChart,string
shipperZIP,string receiverZIP,
string receiverCountry,string pkgWeight,string
isResidential, string isCOD,
string isSatPickup,string isSatDelivery, string pkgType)
{
decimal shippingRate = 0;
WebRequest myWebReq;
WebResponse myWebResp;
StreamReader myStream;
string URLRequest;
string responseLine;

URLRequest =
BuildRequest(svcCode,rateChart,shipperZIP,receiverZIP,"US",pkgWeight,isResidential,isCOD,isSatPickup,isSatDelivery,pkgType);
myWebReq = WebRequest.Create(URLRequest);
myWebResp = myWebReq.GetResponse();

myStream = new StreamReader(myWebResp.GetResponseStream(),
System.Text.Encoding.ASCII);
try
{
responseLine = myStream.ReadLine();

while(responseLine != null)
{
responseLine = myStream.ReadLine();

if (responseLine.Length > 0)
{
if (responseLine.ToLower().IndexOf("upsonline", 0,
responseLine.Length) > -1)
{
string[] arr;
char[] perct = new char[1];
perct[0] = '%';
arr = responseLine.Split(perct);
if (arr[3].Substring(0,11).ToLower() == "0000success")
shippingRate = Convert.ToDecimal(arr[12]);

responseLine = null;
}
}

}


}
catch(Exception e)
{
throw new AppException("Error occured trying to calculate UPS
shiping", e);
}

return shippingRate;
}


private string BuildRequest(string svcCode, string rateChart, string
shipperZIP, string receiverZIP,
string receiverCountry, string pkgWeight, string isResidential,
string isCOD,
string isSatPickup, string isSatDelivery, string pkgType)
{

System.Text.StringBuilder ups = new System.Text.StringBuilder();
ups.Append("http://www.ups.com/using/services/rave/qcost_dss.cgi?");
ups.Append("AppVersion=1.2&AcceptUPSLicenseAgreement=YES&");
ups.Append("ResponseType=application/x-ups-rss&ActionCode=3&");
ups.Append("ServiceLevelCode=" + svcCode + "&RateChart=" + rateChart
+ "&");
ups.Append("ShipperPostalCode=" + shipperZIP +
"&ConsigneePostalCode=" + receiverZIP + "&");
ups.Append("ConsigneeCountry=" + receiverCountry +
"&PackageActualWeight=" + pkgWeight + "&");
ups.Append("ResidentialInd=" + isResidential + "&CODInd=" +
isCOD
+
"&SatDelivInd=" + isSatDelivery);
ups.Append("&SatPickupInd=" + isSatPickup + "&PackagingType=" +
pkgType);

return
ups.ToString();
}


----USPS
[WebMethod]
public decimal GetPrice(string userID, string password, string
zipOrigin, string zipDestination,
string pounds, string ounces, string container, string size, string
service)
{
WebRequest myWebReq;
WebResponse myWebResp;
StreamReader myStream;
string UrlRequest;
decimal shippingRate = 0;

UrlRequest = BuildRequest(userID, password, zipOrigin,
zipDestination, pounds, ounces, container, size, service);

myWebReq = WebRequest.Create(UrlRequest);

try
{
myWebResp = myWebReq.GetResponse();

myStream = new StreamReader(myWebResp.GetResponseStream(),
System.Text.Encoding.ASCII);

XmlTextReader xmlReader = new XmlTextReader(myStream);

System.Text.StringBuilder response = new
System.Text.StringBuilder();

while (xmlReader.Read())
{
if (xmlReader.MoveToContent() == XmlNodeType.Element &&
xmlReader.Name.ToUpper() == "RATE")
{
shippingRate = Convert.ToDecimal(xmlReader.ReadString());
}
}

return shippingRate;
}
catch(Exception e)
{
throw new AppException("Error occured trying to calculate USPS
shiping", e);
}
}

private string BuildRequest(string userID, string password, string
zipOrigin,
string zipDestination, string pounds, string ounces, string
container,
string size, string service)
{
System.Text.StringBuilder usps = new System.Text.StringBuilder();
usps.Append("http://testing.shippingapis.com/ShippingAPITest.dll");
usps.Append( "?API=RateV2&XML=" );
usps.Append( "<RateV2Request USERID=\"" );
usps.Append( userID + "\" " );
usps.Append( "PASSWORD=\"" );
usps.Append( password + "\">" );
usps.Append( "<Package ID=\"0\">" );
usps.Append( "<Service>" + service + "</Service>" );
usps.Append( "<ZipOrigination>" + zipOrigin +
);

usps.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
usps.Append( "<Pounds>" + pounds + "</Pounds>" );
usps.Append( "<Ounces>" + ounces + "</Ounces>" );
usps.Append( "<Container>" + container + "</Container>" );
usps.Append( "<Size>" + size + "</Size>" );
usps.Append( "</Package></RateV2Request>" );

return usps.ToString();
}

ThyRock wrote:
Precept,
I tried the URI object and it will return a uri without encoding if
you pass
the dontencode parameter set to true.
I tried the StringBuilder approach and it worked so I have move
on
to
the
next step.
There are many ways of reaching the same end and I would like very
much to
look at
your approach to using the UPS DHL services.
Thanks,

:

ThyRock,

Thx for the quick response. I see that you are not using as Uri
object
and are passing in a StringBuilder...hmm I will have to try that
hopefully the XML format will be maintained and not encoded. I have
the
UPS shipping code done. I don't know if you want to build the
component
yourself for the experience or whatever..., but I have the code and
can
give it to you if you want to save coding time. BTW I also have the
DHL
component done if you want that one too, or I can give you the info
you
need if you want to code that component yourself..just let me know

Thx Precept


ThyRock wrote:
Precept,
I am also working on a Shipping component, and would be
interested in
any
problems I may encounter on the UPS service. I have got the USPS
service
working and am now going to start on the UPS service. I have
included the
USPS code for you.

replace userid with your USPS UserID
replace userpassword with your USPS Password

string userID = "userid";
string password = "userpassword";
string service = "PRIORITY";
string zipOrigination = "10022";
string zipDestination = "20008";
string pounds = "10";
string ounces = "5";
string container = "Flat Rate Box";
string size = "REGULAR";

StringBuilder stringBuilder = new StringBuilder(
"http://testing.shippingapis.com/ShippingAPITest.dll" );

stringBuilder.Append( "?API=RateV2&XML=" );
stringBuilder.Append( "<RateV2Request USERID=\"" );
stringBuilder.Append( userID + "\" " );
stringBuilder.Append( "PASSWORD=\"" );
stringBuilder.Append( password + "\">" );
stringBuilder.Append( "<Package ID=\"0\">" );
stringBuilder.Append( "<Service>" + service + "</Service>" );
stringBuilder.Append( "<ZipOrigination>" + zipOrigination +
"</ZipOrigination>" );
stringBuilder.Append( "<ZipDestination>" + zipDestination +
"</ZipDestination>" );
stringBuilder.Append( "<Pounds>" + pounds + "</Pounds>" );
stringBuilder.Append( "<Ounces>" + ounces + "</Ounces>" );
stringBuilder.Append( "<Container>" + container +
);
stringBuilder.Append( "<Size>" + size + "</Size>" );
stringBuilder.Append( "</Package></RateV2Request>" );

WebRequest webRequest = WebRequest.Create(
stringBuilder.ToString()
);

try
{
WebResponse webResponse = webRequest.GetResponse();
Stream webResponseStream = webResponse.GetResponseStream();

// txtHTML is a TextArea control to display the raw response
for
development
// purposes.
// You would unpack the xml document here and return the needed
values

Byte[] read = new Byte[512];
int bytes = webResponseStream.Read( read, 0, 512 );

txtHTML.InnerHtml = "";
while ( bytes > 0 )
{
// Note:
// The following assumes that the response uses UTF-8 as
encoding.
// If the content is sent in a ANSI codepage like 932 use
something like
this:
// Encoding encode =
System.Text.Encoding.GetEncoding("shift-jis");
Encoding encode = System.Text.Encoding.GetEncoding(
"utf-8"
);
txtHTML.InnerHtml = txtHTML.InnerHtml + encode.GetString(read,
0,
bytes);
bytes = webResponseStream.Read( read, 0, 512 );

// End of development code.
}
}
catch(Exception)
{
txtHTML.InnerHtml = "Error retrieving page";
}

The above request returns the following response:

<?xml version="1.0"?>
<RateV2Response><Package
Box said:
Mail Flat Rate Box (11.25" x 8.75" x
6") said:
Mail Flat Rate Box (14" x 12" x
3.5") said:
:

ThyRock,

I have been working on trying to pass the userid and password
without
the escape character for a solid week. I came across this
article
and
saw that you encountered the same problem. How did you fix it?
I
currently use an XmlTextWriter, Memory Stream and XmlDocument
objects
to form the xml parameter. I am trying to complete an ecommerce
site
for a friends business. He uses dhl, ups, and usps for his
shipping. I
have 2 of 3 done, but the usps is becoming pesky problem. Do
you
have
any suggestions? Any help would be appreciated

Precept

ThyRock wrote:
Bruce,
Again, thanks very much for your help, I have work out this
problem.


:

I am working on a WebRequest accessing the US Postal
Service
WebTools test API.
This service uses a DLL file (ShippingAPITest.dll) with a
query
string which
includes XML.
The web service accepts the query string with no url
encoding.
I must pass the <> characters as they are in the query
string.
If these characters are url encoded the service rejects the
request.


This API Url is
http://testing.shippingapis.com/ShippingAPITest.dll

It takes a query string as follows:

?API=RateV2&XML=<RateV2Request USERID="userid"
PASSWORD="password">
<Package
ID="0"> <Service>PRIORITY</Service>
<ZipOrigination>10022</ZipOrigination>
<ZipDestination>20008</ZipDestination>
<Ounces>5</Ounces>
<Container>Flat Rate Box</Container>
<Size>REGULAR</Size></Package></RateV2Request>


I can use this url and query string from the location bar
of
the
web
browser and it will return the correct xml response. If
this
query
string is
encoded, the DLL will return an error. The USPS DLL is not
decoding an
encoded query string. The USPS is not up to date with the
latest
Xml
technology and uses the DLL to retreive the query string
and
process the
request.
I am very limited to what I can do with this service
provider.

Can someone tell me how to use the WebRequest method
without
encoding the
request?

Thanks for your help.
 
W

William Lanza

All this code is very helpful, thanks.
I was wondering if anyone is having a problem with Authorization. I am
using the Verify service and I can send the request fine, but the server
comes back with the error that my Username is not Authorized. I have
"Requested permission" and everything.

Any help would be greatly appreciated.

tia
Bill
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top