Connecting Tech Pros Worldwide Help | Site Map

WebRequest method usage

ThyRock
Guest
 
Posts: n/a
#1: Nov 19 '05
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.
bruce barker
Guest
 
Posts: n/a
#2: Nov 19 '05

re: WebRequest method usage


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)


"ThyRock" <ThyRock@discussions.microsoft.com> wrote in message
news:FA818B9D-A297-4EB6-BB95-D29920A54927@microsoft.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.


ThyRock
Guest
 
Posts: n/a
#3: Nov 19 '05

re: WebRequest method usage


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.


"ThyRock" wrote:
[color=blue]
> 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.[/color]
ThyRock
Guest
 
Posts: n/a
#4: Nov 19 '05

re: WebRequest method usage


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


"ThyRock" wrote:
[color=blue]
> 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.[/color]
Precept
Guest
 
Posts: n/a
#5: Nov 19 '05

re: WebRequest method usage


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:[color=blue]
> Bruce,
> Again, thanks very much for your help, I have work out this problem.
>
>
> "ThyRock" wrote:
>[color=green]
> > I am working on a WebRequest accessing the US Postal Service[/color][/color]
WebTools test API.[color=blue][color=green]
> > This service uses a DLL file (ShippingAPITest.dll) with a query[/color][/color]
string which[color=blue][color=green]
> > 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[/color][/color]
request.[color=blue][color=green]
> >
> >
> > 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">[/color][/color]
<Package[color=blue][color=green]
> > ID="0"> <Service>PRIORITY</Service>[/color][/color]
<ZipOrigination>10022</ZipOrigination>[color=blue][color=green]
> > <ZipDestination>20008</ZipDestination> <Pounds>10</Pounds>[/color][/color]
<Ounces>5</Ounces>[color=blue][color=green]
> > <Container>Flat Rate Box</Container>
> > <Size>REGULAR</Size></Package></RateV2Request>
> >
> >
> > I can use this url and query string from the location bar of the[/color][/color]
web[color=blue][color=green]
> > browser and it will return the correct xml response. If this query[/color][/color]
string is[color=blue][color=green]
> > encoded, the DLL will return an error. The USPS DLL is not[/color][/color]
decoding an[color=blue][color=green]
> > encoded query string. The USPS is not up to date with the latest[/color][/color]
Xml[color=blue][color=green]
> > technology and uses the DLL to retreive the query string and[/color][/color]
process the[color=blue][color=green]
> > 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[/color][/color]
encoding the[color=blue][color=green]
> > request?
> >
> > Thanks for your help.[/color][/color]

ThyRock
Guest
 
Posts: n/a
#6: Nov 19 '05

re: WebRequest method usage


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>

"Precept" wrote:
[color=blue]
> 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:[color=green]
> > Bruce,
> > Again, thanks very much for your help, I have work out this problem.
> >
> >
> > "ThyRock" wrote:
> >[color=darkred]
> > > I am working on a WebRequest accessing the US Postal Service[/color][/color]
> WebTools test API.[color=green][color=darkred]
> > > This service uses a DLL file (ShippingAPITest.dll) with a query[/color][/color]
> string which[color=green][color=darkred]
> > > 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[/color][/color]
> request.[color=green][color=darkred]
> > >
> > >
> > > 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">[/color][/color]
> <Package[color=green][color=darkred]
> > > ID="0"> <Service>PRIORITY</Service>[/color][/color]
> <ZipOrigination>10022</ZipOrigination>[color=green][color=darkred]
> > > <ZipDestination>20008</ZipDestination> <Pounds>10</Pounds>[/color][/color]
> <Ounces>5</Ounces>[color=green][color=darkred]
> > > <Container>Flat Rate Box</Container>
> > > <Size>REGULAR</Size></Package></RateV2Request>
> > >
> > >
> > > I can use this url and query string from the location bar of the[/color][/color]
> web[color=green][color=darkred]
> > > browser and it will return the correct xml response. If this query[/color][/color]
> string is[color=green][color=darkred]
> > > encoded, the DLL will return an error. The USPS DLL is not[/color][/color]
> decoding an[color=green][color=darkred]
> > > encoded query string. The USPS is not up to date with the latest[/color][/color]
> Xml[color=green][color=darkred]
> > > technology and uses the DLL to retreive the query string and[/color][/color]
> process the[color=green][color=darkred]
> > > 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[/color][/color]
> encoding the[color=green][color=darkred]
> > > request?
> > >
> > > Thanks for your help.[/color][/color]
>
>[/color]
Precept
Guest
 
Posts: n/a
#7: Nov 19 '05

re: WebRequest method usage


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:[color=blue]
> Precept,
> I am also working on a Shipping component, and would be interested in[/color]
any[color=blue]
> problems I may encounter on the UPS service. I have got the USPS[/color]
service[color=blue]
> working and am now going to start on the UPS service. I have[/color]
included the[color=blue]
> 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()[/color]
);[color=blue]
>
> 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[/color]
values[color=blue]
>
> 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[/color]
something like[color=blue]
> this:
> // Encoding encode =[/color]
System.Text.Encoding.GetEncoding("shift-jis");[color=blue]
> Encoding encode = System.Text.Encoding.GetEncoding( "utf-8" );
> txtHTML.InnerHtml = txtHTML.InnerHtml + encode.GetString(read, 0,[/color]
bytes);[color=blue]
> 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
>[/color]
ID="0"><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat
[color=blue]
> Rate
>[/color]
Box</Container><Size>REGULAR</Size><Zone>3</Zone><Postage><MailService>Priority
[color=blue]
> Mail Flat Rate Box (11.25" x 8.75" x
>[/color]
6")</MailService><Rate>7.70</Rate></Postage><Postage><MailService>Priority
[color=blue]
> Mail Flat Rate Box (14" x 12" x
>[/color]
3.5")</MailService><Rate>7.70</Rate></Postage></Package></RateV2Response>[color=blue]
>
> "Precept" wrote:
>[color=green]
> > ThyRock,
> >
> > I have been working on trying to pass the userid and password[/color][/color]
without[color=blue][color=green]
> > the escape character for a solid week. I came across this article[/color][/color]
and[color=blue][color=green]
> > saw that you encountered the same problem. How did you fix it? I
> > currently use an XmlTextWriter, Memory Stream and XmlDocument[/color][/color]
objects[color=blue][color=green]
> > to form the xml parameter. I am trying to complete an ecommerce[/color][/color]
site[color=blue][color=green]
> > for a friends business. He uses dhl, ups, and usps for his[/color][/color]
shipping. I[color=blue][color=green]
> > have 2 of 3 done, but the usps is becoming pesky problem. Do you[/color][/color]
have[color=blue][color=green]
> > any suggestions? Any help would be appreciated
> >
> > Precept
> >
> > ThyRock wrote:[color=darkred]
> > > Bruce,
> > > Again, thanks very much for your help, I have work out this[/color][/color][/color]
problem.[color=blue][color=green][color=darkred]
> > >
> > >
> > > "ThyRock" wrote:
> > >
> > > > I am working on a WebRequest accessing the US Postal Service[/color]
> > WebTools test API.[color=darkred]
> > > > This service uses a DLL file (ShippingAPITest.dll) with a query[/color]
> > string which[color=darkred]
> > > > 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[/color]
> > request.[color=darkred]
> > > >
> > > >
> > > > This API Url is
> > > > http://testing.shippingapis.com/ShippingAPITest.dll
> > > >
> > > > It takes a query string as follows:
> > > >
> > > > ?API=RateV2&XML=<RateV2Request USERID="userid"[/color][/color][/color]
PASSWORD="password">[color=blue][color=green]
> > <Package[color=darkred]
> > > > ID="0"> <Service>PRIORITY</Service>[/color]
> > <ZipOrigination>10022</ZipOrigination>[color=darkred]
> > > > <ZipDestination>20008</ZipDestination> <Pounds>10</Pounds>[/color]
> > <Ounces>5</Ounces>[color=darkred]
> > > > <Container>Flat Rate Box</Container>
> > > > <Size>REGULAR</Size></Package></RateV2Request>
> > > >
> > > >
> > > > I can use this url and query string from the location bar of[/color][/color][/color]
the[color=blue][color=green]
> > web[color=darkred]
> > > > browser and it will return the correct xml response. If this[/color][/color][/color]
query[color=blue][color=green]
> > string is[color=darkred]
> > > > encoded, the DLL will return an error. The USPS DLL is not[/color]
> > decoding an[color=darkred]
> > > > encoded query string. The USPS is not up to date with the[/color][/color][/color]
latest[color=blue][color=green]
> > Xml[color=darkred]
> > > > technology and uses the DLL to retreive the query string and[/color]
> > process the[color=darkred]
> > > > 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[/color]
> > encoding the[color=darkred]
> > > > request?
> > > >
> > > > Thanks for your help.[/color]
> >
> >[/color][/color]

ThyRock
Guest
 
Posts: n/a
#8: Nov 19 '05

re: WebRequest method usage


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" wrote:
[color=blue]
> 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:[color=green]
> > Precept,
> > I am also working on a Shipping component, and would be interested in[/color]
> any[color=green]
> > problems I may encounter on the UPS service. I have got the USPS[/color]
> service[color=green]
> > working and am now going to start on the UPS service. I have[/color]
> included the[color=green]
> > 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()[/color]
> );[color=green]
> >
> > 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[/color]
> values[color=green]
> >
> > 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[/color]
> something like[color=green]
> > this:
> > // Encoding encode =[/color]
> System.Text.Encoding.GetEncoding("shift-jis");[color=green]
> > Encoding encode = System.Text.Encoding.GetEncoding( "utf-8" );
> > txtHTML.InnerHtml = txtHTML.InnerHtml + encode.GetString(read, 0,[/color]
> bytes);[color=green]
> > 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
> >[/color]
> ID="0"><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat
>[color=green]
> > Rate
> >[/color]
> Box</Container><Size>REGULAR</Size><Zone>3</Zone><Postage><MailService>Priority
>[color=green]
> > Mail Flat Rate Box (11.25" x 8.75" x
> >[/color]
> 6")</MailService><Rate>7.70</Rate></Postage><Postage><MailService>Priority
>[color=green]
> > Mail Flat Rate Box (14" x 12" x
> >[/color]
> 3.5")</MailService><Rate>7.70</Rate></Postage></Package></RateV2Response>[color=green]
> >
> > "Precept" wrote:
> >[color=darkred]
> > > ThyRock,
> > >
> > > I have been working on trying to pass the userid and password[/color][/color]
> without[color=green][color=darkred]
> > > the escape character for a solid week. I came across this article[/color][/color]
> and[color=green][color=darkred]
> > > saw that you encountered the same problem. How did you fix it? I
> > > currently use an XmlTextWriter, Memory Stream and XmlDocument[/color][/color]
> objects[color=green][color=darkred]
> > > to form the xml parameter. I am trying to complete an ecommerce[/color][/color]
> site[color=green][color=darkred]
> > > for a friends business. He uses dhl, ups, and usps for his[/color][/color]
> shipping. I[color=green][color=darkred]
> > > have 2 of 3 done, but the usps is becoming pesky problem. Do you[/color][/color]
> have[color=green][color=darkred]
> > > any suggestions? Any help would be appreciated
> > >
> > > Precept
> > >
> > > ThyRock wrote:
> > > > Bruce,
> > > > Again, thanks very much for your help, I have work out this[/color][/color]
> problem.[color=green][color=darkred]
> > > >
> > > >
> > > > "ThyRock" wrote:
> > > >
> > > > > 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"[/color][/color]
> PASSWORD="password">[color=green][color=darkred]
> > > <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[/color][/color]
> the[color=green][color=darkred]
> > > web
> > > > > browser and it will return the correct xml response. If this[/color][/color]
> query[color=green][color=darkred]
> > > 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[/color][/color]
> latest[color=green][color=darkred]
> > > 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.
> > >
> > >[/color][/color]
>
>[/color]
Precept
Guest
 
Posts: n/a
#9: Nov 19 '05

re: WebRequest method usage


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,receiver ZIP,"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&AcceptUPSLicenseAgreeme nt=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();
}

ThyRock wrote:[color=blue]
> Precept,
> I tried the URI object and it will return a uri without encoding if[/color]
you pass[color=blue]
> the dontencode parameter set to true.
> I tried the StringBuilder approach and it worked so I have move on to[/color]
the[color=blue]
> next step.
> There are many ways of reaching the same end and I would like very[/color]
much to[color=blue]
> look at
> your approach to using the UPS DHL services.
> Thanks,
>
> "Precept" wrote:
>[color=green]
> > ThyRock,
> >
> > Thx for the quick response. I see that you are not using as Uri[/color][/color]
object[color=blue][color=green]
> > 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[/color][/color]
the[color=blue][color=green]
> > UPS shipping code done. I don't know if you want to build the[/color][/color]
component[color=blue][color=green]
> > yourself for the experience or whatever..., but I have the code and[/color][/color]
can[color=blue][color=green]
> > give it to you if you want to save coding time. BTW I also have the[/color][/color]
DHL[color=blue][color=green]
> > component done if you want that one too, or I can give you the info[/color][/color]
you[color=blue][color=green]
> > need if you want to code that component yourself..just let me know
> >
> > Thx Precept
> >
> >
> > ThyRock wrote:[color=darkred]
> > > Precept,
> > > I am also working on a Shipping component, and would be[/color][/color][/color]
interested in[color=blue][color=green]
> > any[color=darkred]
> > > problems I may encounter on the UPS service. I have got the USPS[/color]
> > service[color=darkred]
> > > working and am now going to start on the UPS service. I have[/color]
> > included the[color=darkred]
> > > 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>"[/color][/color][/color]
);[color=blue][color=green][color=darkred]
> > > stringBuilder.Append( "<Size>" + size + "</Size>" );
> > > stringBuilder.Append( "</Package></RateV2Request>" );
> > >
> > > WebRequest webRequest = WebRequest.Create([/color][/color][/color]
stringBuilder.ToString()[color=blue][color=green]
> > );[color=darkred]
> > >
> > > try
> > > {
> > > WebResponse webResponse = webRequest.GetResponse();
> > > Stream webResponseStream = webResponse.GetResponseStream();
> > >
> > > // txtHTML is a TextArea control to display the raw response[/color][/color][/color]
for[color=blue][color=green][color=darkred]
> > > development
> > > // purposes.
> > > // You would unpack the xml document here and return the needed[/color]
> > values[color=darkred]
> > >
> > > 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[/color][/color][/color]
encoding.[color=blue][color=green][color=darkred]
> > > // If the content is sent in a ANSI codepage like 932 use[/color]
> > something like[color=darkred]
> > > this:
> > > // Encoding encode =[/color]
> > System.Text.Encoding.GetEncoding("shift-jis");[color=darkred]
> > > Encoding encode = System.Text.Encoding.GetEncoding( "utf-8" );
> > > txtHTML.InnerHtml = txtHTML.InnerHtml + encode.GetString(read,[/color][/color][/color]
0,[color=blue][color=green]
> > bytes);[color=darkred]
> > > 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
> > >[/color]
> >[/color][/color]
ID="0"><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat[color=blue][color=green]
> >[color=darkred]
> > > Rate
> > >[/color]
> >[/color][/color]
Box</Container><Size>REGULAR</Size><Zone>3</Zone><Postage><MailService>Priority[color=blue][color=green]
> >[color=darkred]
> > > Mail Flat Rate Box (11.25" x 8.75" x
> > >[/color]
> >[/color][/color]
6")</MailService><Rate>7.70</Rate></Postage><Postage><MailService>Priority[color=blue][color=green]
> >[color=darkred]
> > > Mail Flat Rate Box (14" x 12" x
> > >[/color]
> >[/color][/color]
3.5")</MailService><Rate>7.70</Rate></Postage></Package></RateV2Response>[color=blue][color=green][color=darkred]
> > >
> > > "Precept" wrote:
> > >
> > > > ThyRock,
> > > >
> > > > I have been working on trying to pass the userid and password[/color]
> > without[color=darkred]
> > > > the escape character for a solid week. I came across this[/color][/color][/color]
article[color=blue][color=green]
> > and[color=darkred]
> > > > saw that you encountered the same problem. How did you fix it?[/color][/color][/color]
I[color=blue][color=green][color=darkred]
> > > > currently use an XmlTextWriter, Memory Stream and XmlDocument[/color]
> > objects[color=darkred]
> > > > to form the xml parameter. I am trying to complete an ecommerce[/color]
> > site[color=darkred]
> > > > for a friends business. He uses dhl, ups, and usps for his[/color]
> > shipping. I[color=darkred]
> > > > have 2 of 3 done, but the usps is becoming pesky problem. Do[/color][/color][/color]
you[color=blue][color=green]
> > have[color=darkred]
> > > > any suggestions? Any help would be appreciated
> > > >
> > > > Precept
> > > >
> > > > ThyRock wrote:
> > > > > Bruce,
> > > > > Again, thanks very much for your help, I have work out this[/color]
> > problem.[color=darkred]
> > > > >
> > > > >
> > > > > "ThyRock" wrote:
> > > > >
> > > > > > I am working on a WebRequest accessing the US Postal[/color][/color][/color]
Service[color=blue][color=green][color=darkred]
> > > > WebTools test API.
> > > > > > This service uses a DLL file (ShippingAPITest.dll) with a[/color][/color][/color]
query[color=blue][color=green][color=darkred]
> > > > string which
> > > > > > includes XML.
> > > > > > The web service accepts the query string with no url[/color][/color][/color]
encoding.[color=blue][color=green][color=darkred]
> > > > > > I must pass the <> characters as they are in the query[/color][/color][/color]
string.[color=blue][color=green][color=darkred]
> > > > > > 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"[/color]
> > PASSWORD="password">[color=darkred]
> > > > <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[/color][/color][/color]
of[color=blue][color=green]
> > the[color=darkred]
> > > > web
> > > > > > browser and it will return the correct xml response. If[/color][/color][/color]
this[color=blue][color=green]
> > query[color=darkred]
> > > > 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[/color]
> > latest[color=darkred]
> > > > Xml
> > > > > > technology and uses the DLL to retreive the query string[/color][/color][/color]
and[color=blue][color=green][color=darkred]
> > > > process the
> > > > > > request.
> > > > > > I am very limited to what I can do with this service[/color][/color][/color]
provider.[color=blue][color=green][color=darkred]
> > > > > >
> > > > > > Can someone tell me how to use the WebRequest method[/color][/color][/color]
without[color=blue][color=green][color=darkred]
> > > > encoding the
> > > > > > request?
> > > > > >
> > > > > > Thanks for your help.
> > > >
> > > >[/color]
> >
> >[/color][/color]

Precept
Guest
 
Posts: n/a
#10: Nov 19 '05

re: WebRequest method usage


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

Precept wrote:[color=blue]
> 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[/color]
develop....here[color=blue]
> 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[/color]
stringbuilder[color=blue]
> 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[/color]
you[color=blue]
> 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 =
>[/color]
BuildRequest(svcCode,rateChart,shipperZIP,receiver ZIP,"US",pkgWeight,isResidential,isCOD,isSatPickup ,isSatDelivery,pkgType);[color=blue]
>
>
> 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();
>
>[/color]
ups.Append("http://www.ups.com/using/services/rave/qcost_dss.cgi?");[color=blue]
> ups.Append("AppVersion=1.2&AcceptUPSLicenseAgreeme nt=YES&");
> ups.Append("ResponseType=application/x-ups-rss&ActionCode=3&");
> ups.Append("ServiceLevelCode=" + svcCode + "&RateChart=" +[/color]
rateChart[color=blue]
> + "&");
> ups.Append("ShipperPostalCode=" + shipperZIP +
> "&ConsigneePostalCode=" + receiverZIP + "&");
> ups.Append("ConsigneeCountry=" + receiverCountry +
> "&PackageActualWeight=" + pkgWeight + "&");
> ups.Append("ResidentialInd=" + isResidential + "&CODInd=" + isCOD[/color]
+[color=blue]
> "&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,[/color]
string[color=blue]
> 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();
>[/color]
usps.Append("http://testing.shippingapis.com/ShippingAPITest.dll");[color=blue]
> 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>"[/color]
);[color=blue]
>
> 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:[color=green]
> > Precept,
> > I tried the URI object and it will return a uri without encoding if[/color]
> you pass[color=green]
> > the dontencode parameter set to true.
> > I tried the StringBuilder approach and it worked so I have move on[/color][/color]
to[color=blue]
> the[color=green]
> > next step.
> > There are many ways of reaching the same end and I would like very[/color]
> much to[color=green]
> > look at
> > your approach to using the UPS DHL services.
> > Thanks,
> >
> > "Precept" wrote:
> >[color=darkred]
> > > ThyRock,
> > >
> > > Thx for the quick response. I see that you are not using as Uri[/color][/color]
> object[color=green][color=darkred]
> > > and are passing in a StringBuilder...hmm I will have to try that
> > > hopefully the XML format will be maintained and not encoded. I[/color][/color][/color]
have[color=blue]
> the[color=green][color=darkred]
> > > UPS shipping code done. I don't know if you want to build the[/color][/color]
> component[color=green][color=darkred]
> > > yourself for the experience or whatever..., but I have the code[/color][/color][/color]
and[color=blue]
> can[color=green][color=darkred]
> > > give it to you if you want to save coding time. BTW I also have[/color][/color][/color]
the[color=blue]
> DHL[color=green][color=darkred]
> > > component done if you want that one too, or I can give you the[/color][/color][/color]
info[color=blue]
> you[color=green][color=darkred]
> > > need if you want to code that component yourself..just let me[/color][/color][/color]
know[color=blue][color=green][color=darkred]
> > >
> > > Thx Precept
> > >
> > >
> > > ThyRock wrote:
> > > > Precept,
> > > > I am also working on a Shipping component, and would be[/color][/color]
> interested in[color=green][color=darkred]
> > > any
> > > > problems I may encounter on the UPS service. I have got the[/color][/color][/color]
USPS[color=blue][color=green][color=darkred]
> > > 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 +[/color][/color][/color]
"</Container>"[color=blue]
> );[color=green][color=darkred]
> > > > stringBuilder.Append( "<Size>" + size + "</Size>" );
> > > > stringBuilder.Append( "</Package></RateV2Request>" );
> > > >
> > > > WebRequest webRequest = WebRequest.Create([/color][/color]
> stringBuilder.ToString()[color=green][color=darkred]
> > > );
> > > >
> > > > try
> > > > {
> > > > WebResponse webResponse = webRequest.GetResponse();
> > > > Stream webResponseStream = webResponse.GetResponseStream();
> > > >
> > > > // txtHTML is a TextArea control to display the raw response[/color][/color]
> for[color=green][color=darkred]
> > > > development
> > > > // purposes.
> > > > // You would unpack the xml document here and return the[/color][/color][/color]
needed[color=blue][color=green][color=darkred]
> > > 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[/color][/color]
> encoding.[color=green][color=darkred]
> > > > // 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"[/color][/color][/color]
);[color=blue][color=green][color=darkred]
> > > > txtHTML.InnerHtml = txtHTML.InnerHtml +[/color][/color][/color]
encode.GetString(read,[color=blue]
> 0,[color=green][color=darkred]
> > > 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
> > > >
> > >[/color][/color]
>[/color]
ID="0"><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat[color=blue][color=green][color=darkred]
> > >
> > > > Rate
> > > >
> > >[/color][/color]
>[/color]
Box</Container><Size>REGULAR</Size><Zone>3</Zone><Postage><MailService>Priority[color=blue][color=green][color=darkred]
> > >
> > > > Mail Flat Rate Box (11.25" x 8.75" x
> > > >
> > >[/color][/color]
>[/color]
6")</MailService><Rate>7.70</Rate></Postage><Postage><MailService>Priority[color=blue][color=green][color=darkred]
> > >
> > > > Mail Flat Rate Box (14" x 12" x
> > > >
> > >[/color][/color]
>[/color]
3.5")</MailService><Rate>7.70</Rate></Postage></Package></RateV2Response>[color=blue][color=green][color=darkred]
> > > >
> > > > "Precept" wrote:
> > > >
> > > > > 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[/color][/color]
> article[color=green][color=darkred]
> > > and
> > > > > saw that you encountered the same problem. How did you fix[/color][/color][/color]
it?[color=blue]
> I[color=green][color=darkred]
> > > > > currently use an XmlTextWriter, Memory Stream and XmlDocument
> > > objects
> > > > > to form the xml parameter. I am trying to complete an[/color][/color][/color]
ecommerce[color=blue][color=green][color=darkred]
> > > 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[/color][/color]
> you[color=green][color=darkred]
> > > 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.
> > > > > >
> > > > > >
> > > > > > "ThyRock" wrote:
> > > > > >
> > > > > > > I am working on a WebRequest accessing the US Postal[/color][/color]
> Service[color=green][color=darkred]
> > > > > WebTools test API.
> > > > > > > This service uses a DLL file (ShippingAPITest.dll) with a[/color][/color]
> query[color=green][color=darkred]
> > > > > string which
> > > > > > > includes XML.
> > > > > > > The web service accepts the query string with no url[/color][/color]
> encoding.[color=green][color=darkred]
> > > > > > > I must pass the <> characters as they are in the query[/color][/color]
> string.[color=green][color=darkred]
> > > > > > > If these characters are url encoded the service rejects[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > > 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>[/color][/color][/color]
<Pounds>10</Pounds>[color=blue][color=green][color=darkred]
> > > > > <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[/color][/color]
> of[color=green][color=darkred]
> > > the
> > > > > web
> > > > > > > browser and it will return the correct xml response. If[/color][/color]
> this[color=green][color=darkred]
> > > query
> > > > > string is
> > > > > > > encoded, the DLL will return an error. The USPS DLL is[/color][/color][/color]
not[color=blue][color=green][color=darkred]
> > > > > decoding an
> > > > > > > encoded query string. The USPS is not up to date with[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > latest
> > > > > Xml
> > > > > > > technology and uses the DLL to retreive the query string[/color][/color]
> and[color=green][color=darkred]
> > > > > process the
> > > > > > > request.
> > > > > > > I am very limited to what I can do with this service[/color][/color]
> provider.[color=green][color=darkred]
> > > > > > >
> > > > > > > Can someone tell me how to use the WebRequest method[/color][/color]
> without[color=green][color=darkred]
> > > > > encoding the
> > > > > > > request?
> > > > > > >
> > > > > > > Thanks for your help.
> > > > >
> > > > >
> > >
> > >[/color][/color][/color]

Precept
Guest
 
Posts: n/a
#11: Nov 19 '05

re: WebRequest method usage


ThyRock,

I have it working....let me know if you need help with the code....
email me precept33@hotmail.com

Precept

Precept wrote:[color=blue]
> 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[/color]
am[color=blue]
> using the example they provided...I should have it figured out by
> tonight
>
> Precept
>
> Precept wrote:[color=green]
> > ThyRock,
> >
> > Sorry to get back to you so late...was at work late and just[/color][/color]
finished[color=blue][color=green]
> > with the family thing dinner etc.....
> > I used the HTML developers guide because it was easy to[/color]
> develop....here[color=green]
> > is the code along with my USPS code
> > I am using webservices for all three DHL, UPS, and USPS...damn[/color][/color]
fedex[color=blue][color=green]
> > can't get there stinkin docs! I changed my USPS code to a[/color]
> stringbuilder[color=green]
> > 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[/color]
> you[color=green]
> > 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[/color][/color]
till[color=blue][color=green]
> > then..otherwise this one works
> >
> > Cheers,
> >
> > Precept
> >
> > -----UPS
> > [WebMethod]
> > public decimal GetPrice(string svcCode, string rateChart,string
> > shipperZIP,string receiverZIP,
> > string receiverCountry,string[/color][/color]
pkgWeight,string[color=blue][color=green]
> > isResidential, string isCOD,
> > string isSatPickup,string isSatDelivery, string pkgType)
> > {
> > decimal shippingRate = 0;
> > WebRequest myWebReq;
> > WebResponse myWebResp;
> > StreamReader myStream;
> > string URLRequest;
> > string responseLine;
> >
> > URLRequest =
> >[/color]
>[/color]
BuildRequest(svcCode,rateChart,shipperZIP,receiver ZIP,"US",pkgWeight,isResidential,isCOD,isSatPickup ,isSatDelivery,pkgType);[color=blue][color=green]
> >
> >
> > 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,[/color][/color]
string[color=blue][color=green]
> > 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();
> >
> >[/color]
>[/color]
ups.Append("http://www.ups.com/using/services/rave/qcost_dss.cgi?");[color=blue][color=green]
> > ups.Append("AppVersion=1.2&AcceptUPSLicenseAgreeme nt=YES&");
> > ups.Append("ResponseType=application/x-ups-rss&ActionCode=3&");
> > ups.Append("ServiceLevelCode=" + svcCode + "&RateChart=" +[/color]
> rateChart[color=green]
> > + "&");
> > ups.Append("ShipperPostalCode=" + shipperZIP +
> > "&ConsigneePostalCode=" + receiverZIP + "&");
> > ups.Append("ConsigneeCountry=" + receiverCountry +
> > "&PackageActualWeight=" + pkgWeight + "&");
> > ups.Append("ResidentialInd=" + isResidential + "&CODInd=" +[/color][/color]
isCOD[color=blue]
> +[color=green]
> > "&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,[/color]
> string[color=green]
> > 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,[/color][/color]
string[color=blue][color=green]
> > zipOrigin,
> > string zipDestination, string pounds, string ounces, string
> > container,
> > string size, string service)
> > {
> > System.Text.StringBuilder usps = new[/color][/color]
System.Text.StringBuilder();[color=blue][color=green]
> >[/color]
>[/color]
usps.Append("http://testing.shippingapis.com/ShippingAPITest.dll");[color=blue][color=green]
> > 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 +[/color][/color]
"</ZipOrigination>"[color=blue]
> );[color=green]
> >
> > 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:[color=darkred]
> > > Precept,
> > > I tried the URI object and it will return a uri without encoding[/color][/color][/color]
if[color=blue][color=green]
> > you pass[color=darkred]
> > > the dontencode parameter set to true.
> > > I tried the StringBuilder approach and it worked so I have move[/color][/color][/color]
on[color=blue]
> to[color=green]
> > the[color=darkred]
> > > next step.
> > > There are many ways of reaching the same end and I would like[/color][/color][/color]
very[color=blue][color=green]
> > much to[color=darkred]
> > > look at
> > > your approach to using the UPS DHL services.
> > > Thanks,
> > >
> > > "Precept" wrote:
> > >
> > > > ThyRock,
> > > >
> > > > Thx for the quick response. I see that you are not using as Uri[/color]
> > object[color=darkred]
> > > > and are passing in a StringBuilder...hmm I will have to try[/color][/color][/color]
that[color=blue][color=green][color=darkred]
> > > > hopefully the XML format will be maintained and not encoded. I[/color][/color]
> have[color=green]
> > the[color=darkred]
> > > > UPS shipping code done. I don't know if you want to build the[/color]
> > component[color=darkred]
> > > > yourself for the experience or whatever..., but I have the code[/color][/color]
> and[color=green]
> > can[color=darkred]
> > > > give it to you if you want to save coding time. BTW I also have[/color][/color]
> the[color=green]
> > DHL[color=darkred]
> > > > component done if you want that one too, or I can give you the[/color][/color]
> info[color=green]
> > you[color=darkred]
> > > > need if you want to code that component yourself..just let me[/color][/color]
> know[color=green][color=darkred]
> > > >
> > > > Thx Precept
> > > >
> > > >
> > > > ThyRock wrote:
> > > > > Precept,
> > > > > I am also working on a Shipping component, and would be[/color]
> > interested in[color=darkred]
> > > > any
> > > > > problems I may encounter on the UPS service. I have got the[/color][/color]
> USPS[color=green][color=darkred]
> > > > 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 +[/color][/color]
> "</Container>"[color=green]
> > );[color=darkred]
> > > > > stringBuilder.Append( "<Size>" + size + "</Size>" );
> > > > > stringBuilder.Append( "</Package></RateV2Request>" );
> > > > >
> > > > > WebRequest webRequest = WebRequest.Create([/color]
> > stringBuilder.ToString()[color=darkred]
> > > > );
> > > > >
> > > > > try
> > > > > {
> > > > > WebResponse webResponse = webRequest.GetResponse();
> > > > > Stream webResponseStream = webResponse.GetResponseStream();
> > > > >
> > > > > // txtHTML is a TextArea control to display the raw[/color][/color][/color]
response[color=blue][color=green]
> > for[color=darkred]
> > > > > development
> > > > > // purposes.
> > > > > // You would unpack the xml document here and return the[/color][/color]
> needed[color=green][color=darkred]
> > > > 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[/color]
> > encoding.[color=darkred]
> > > > > // 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([/color][/color][/color]
"utf-8"[color=blue]
> );[color=green][color=darkred]
> > > > > txtHTML.InnerHtml = txtHTML.InnerHtml +[/color][/color]
> encode.GetString(read,[color=green]
> > 0,[color=darkred]
> > > > 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
> > > > >
> > > >[/color]
> >[/color]
>[/color]
ID="0"><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat[color=blue][color=green][color=darkred]
> > > >
> > > > > Rate
> > > > >
> > > >[/color]
> >[/color]
>[/color]
Box</Container><Size>REGULAR</Size><Zone>3</Zone><Postage><MailService>Priority[color=blue][color=green][color=darkred]
> > > >
> > > > > Mail Flat Rate Box (11.25" x 8.75" x
> > > > >
> > > >[/color]
> >[/color]
>[/color]
6")</MailService><Rate>7.70</Rate></Postage><Postage><MailService>Priority[color=blue][color=green][color=darkred]
> > > >
> > > > > Mail Flat Rate Box (14" x 12" x
> > > > >
> > > >[/color]
> >[/color]
>[/color]
3.5")</MailService><Rate>7.70</Rate></Postage></Package></RateV2Response>[color=blue][color=green][color=darkred]
> > > > >
> > > > > "Precept" wrote:
> > > > >
> > > > > > ThyRock,
> > > > > >
> > > > > > I have been working on trying to pass the userid and[/color][/color][/color]
password[color=blue][color=green][color=darkred]
> > > > without
> > > > > > the escape character for a solid week. I came across this[/color]
> > article[color=darkred]
> > > > and
> > > > > > saw that you encountered the same problem. How did you fix[/color][/color]
> it?[color=green]
> > I[color=darkred]
> > > > > > currently use an XmlTextWriter, Memory Stream and[/color][/color][/color]
XmlDocument[color=blue][color=green][color=darkred]
> > > > objects
> > > > > > to form the xml parameter. I am trying to complete an[/color][/color]
> ecommerce[color=green][color=darkred]
> > > > 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.[/color][/color][/color]
Do[color=blue][color=green]
> > you[color=darkred]
> > > > have
> > > > > > any suggestions? Any help would be appreciated
> > > > > >
> > > > > > Precept
> > > > > >
> > > > > > ThyRock wrote:
> > > > > > > Bruce,
> > > > > > > Again, thanks very much for your help, I have work out[/color][/color][/color]
this[color=blue][color=green][color=darkred]
> > > > problem.
> > > > > > >
> > > > > > >
> > > > > > > "ThyRock" wrote:
> > > > > > >
> > > > > > > > I am working on a WebRequest accessing the US Postal[/color]
> > Service[color=darkred]
> > > > > > WebTools test API.
> > > > > > > > This service uses a DLL file (ShippingAPITest.dll) with[/color][/color][/color]
a[color=blue][color=green]
> > query[color=darkred]
> > > > > > string which
> > > > > > > > includes XML.
> > > > > > > > The web service accepts the query string with no url[/color]
> > encoding.[color=darkred]
> > > > > > > > I must pass the <> characters as they are in the query[/color]
> > string.[color=darkred]
> > > > > > > > If these characters are url encoded the service rejects[/color][/color]
> the[color=green][color=darkred]
> > > > > > 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>[/color][/color]
> <Pounds>10</Pounds>[color=green][color=darkred]
> > > > > > <Ounces>5</Ounces>
> > > > > > > > <Container>Flat Rate Box</Container>
> > > > > > > > <Size>REGULAR</Size></Package></RateV2Request>
> > > > > > > >
> > > > > > > >
> > > > > > > > I can use this url and query string from the location[/color][/color][/color]
bar[color=blue][color=green]
> > of[color=darkred]
> > > > the
> > > > > > web
> > > > > > > > browser and it will return the correct xml response.[/color][/color][/color]
If[color=blue][color=green]
> > this[color=darkred]
> > > > query
> > > > > > string is
> > > > > > > > encoded, the DLL will return an error. The USPS DLL is[/color][/color]
> not[color=green][color=darkred]
> > > > > > decoding an
> > > > > > > > encoded query string. The USPS is not up to date with[/color][/color]
> the[color=green][color=darkred]
> > > > latest
> > > > > > Xml
> > > > > > > > technology and uses the DLL to retreive the query[/color][/color][/color]
string[color=blue][color=green]
> > and[color=darkred]
> > > > > > process the
> > > > > > > > request.
> > > > > > > > I am very limited to what I can do with this service[/color]
> > provider.[color=darkred]
> > > > > > > >
> > > > > > > > Can someone tell me how to use the WebRequest method[/color]
> > without[color=darkred]
> > > > > > encoding the
> > > > > > > > request?
> > > > > > > >
> > > > > > > > Thanks for your help.
> > > > > >
> > > > > >
> > > >
> > > >[/color][/color][/color]

Chris
Guest
 
Posts: n/a
#12: Nov 19 '05

re: WebRequest method usage


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

Thanks

"Precept" wrote:
[color=blue]
> ThyRock,
>
> I have it working....let me know if you need help with the code....
> email me precept33@hotmail.com
>
> Precept
>
> Precept wrote:[color=green]
> > 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[/color]
> am[color=green]
> > using the example they provided...I should have it figured out by
> > tonight
> >
> > Precept
> >
> > Precept wrote:[color=darkred]
> > > ThyRock,
> > >
> > > Sorry to get back to you so late...was at work late and just[/color][/color]
> finished[color=green][color=darkred]
> > > with the family thing dinner etc.....
> > > I used the HTML developers guide because it was easy to[/color]
> > develop....here[color=darkred]
> > > is the code along with my USPS code
> > > I am using webservices for all three DHL, UPS, and USPS...damn[/color][/color]
> fedex[color=green][color=darkred]
> > > can't get there stinkin docs! I changed my USPS code to a[/color]
> > stringbuilder[color=darkred]
> > > 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[/color]
> > you[color=darkred]
> > > 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[/color][/color]
> till[color=green][color=darkred]
> > > then..otherwise this one works
> > >
> > > Cheers,
> > >
> > > Precept
> > >
> > > -----UPS
> > > [WebMethod]
> > > public decimal GetPrice(string svcCode, string rateChart,string
> > > shipperZIP,string receiverZIP,
> > > string receiverCountry,string[/color][/color]
> pkgWeight,string[color=green][color=darkred]
> > > isResidential, string isCOD,
> > > string isSatPickup,string isSatDelivery, string pkgType)
> > > {
> > > decimal shippingRate = 0;
> > > WebRequest myWebReq;
> > > WebResponse myWebResp;
> > > StreamReader myStream;
> > > string URLRequest;
> > > string responseLine;
> > >
> > > URLRequest =
> > >[/color]
> >[/color]
> BuildRequest(svcCode,rateChart,shipperZIP,receiver ZIP,"US",pkgWeight,isResidential,isCOD,isSatPickup ,isSatDelivery,pkgType);[color=green][color=darkred]
> > >
> > >
> > > 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,[/color][/color]
> string[color=green][color=darkred]
> > > 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();
> > >
> > >[/color]
> >[/color]
> ups.Append("http://www.ups.com/using/services/rave/qcost_dss.cgi?");[color=green][color=darkred]
> > > ups.Append("AppVersion=1.2&AcceptUPSLicenseAgreeme nt=YES&");
> > > ups.Append("ResponseType=application/x-ups-rss&ActionCode=3&");
> > > ups.Append("ServiceLevelCode=" + svcCode + "&RateChart=" +[/color]
> > rateChart[color=darkred]
> > > + "&");
> > > ups.Append("ShipperPostalCode=" + shipperZIP +
> > > "&ConsigneePostalCode=" + receiverZIP + "&");
> > > ups.Append("ConsigneeCountry=" + receiverCountry +
> > > "&PackageActualWeight=" + pkgWeight + "&");
> > > ups.Append("ResidentialInd=" + isResidential + "&CODInd=" +[/color][/color]
> isCOD[color=green]
> > +[color=darkred]
> > > "&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,[/color]
> > string[color=darkred]
> > > 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,[/color][/color]
> string[color=green][color=darkred]
> > > zipOrigin,
> > > string zipDestination, string pounds, string ounces, string
> > > container,
> > > string size, string service)
> > > {
> > > System.Text.StringBuilder usps = new[/color][/color]
> System.Text.StringBuilder();[color=green][color=darkred]
> > >[/color]
> >[/color]
> usps.Append("http://testing.shippingapis.com/ShippingAPITest.dll");[color=green][color=darkred]
> > > 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 +[/color][/color]
> "</ZipOrigination>"[color=green]
> > );[color=darkred]
> > >
> > > 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[/color][/color]
> if[color=green][color=darkred]
> > > you pass
> > > > the dontencode parameter set to true.
> > > > I tried the StringBuilder approach and it worked so I have move[/color][/color]
> on[color=green]
> > to[color=darkred]
> > > the
> > > > next step.
> > > > There are many ways of reaching the same end and I would like[/color][/color]
> very[color=green][color=darkred]
> > > much to
> > > > look at
> > > > your approach to using the UPS DHL services.
> > > > Thanks,
> > > >
> > > > "Precept" wrote:
> > > >
> > > > > 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[/color][/color]
> that[color=green][color=darkred]
> > > > > hopefully the XML format will be maintained and not encoded. I[/color]
> > have[color=darkred]
> > > 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[/color]
> > and[color=darkred]
> > > can
> > > > > give it to you if you want to save coding time. BTW I also have[/color]
> > the[color=darkred]
> > > DHL
> > > > > component done if you want that one too, or I can give you the[/color]
> > info[color=darkred]
> > > you
> > > > > need if you want to code that component yourself..just let me[/color]
> > know[color=darkred]
> > > > >
> > > > > 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[/color]
> > USPS[color=darkred]
> > > > > 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 +[/color]
> > "</Container>"[color=darkred]
> > > );
> > > > > > 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[/color][/color]
> response[color=green][color=darkred]
> > > for
> > > > > > development
> > > > > > // purposes.
> > > > > > // You would unpack the xml document here and return the[/color]
> > needed[color=darkred]
> > > > > 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([/color][/color]
> "utf-8"[color=green]
> > );[color=darkred]
> > > > > > txtHTML.InnerHtml = txtHTML.InnerHtml +[/color]
> > encode.GetString(read,[color=darkred]
> > > 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
> > > > > >
> > > > >
> > >[/color]
> >[/color]
> ID="0"><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat[color=green][color=darkred]
> > > > >
> > > > > > Rate
> > > > > >
> > > > >
> > >[/color]
> >[/color]
> Box</Container><Size>REGULAR</Size><Zone>3</Zone><Postage><MailService>Priority[color=green][color=darkred]
> > > > >
> > > > > > Mail Flat Rate Box (11.25" x 8.75" x
> > > > > >
> > > > >
> > >[/color]
> >[/color]
> 6")</MailService><Rate>7.70</Rate></Postage><Postage><MailService>Priority[color=green][color=darkred]
> > > > >
> > > > > > Mail Flat Rate Box (14" x 12" x
> > > > > >
> > > > >
> > >[/color]
> >[/color]
> 3.5")</MailService><Rate>7.70</Rate></Postage></Package></RateV2Response>[color=green][color=darkred]
> > > > > >
> > > > > > "Precept" wrote:
> > > > > >
> > > > > > > ThyRock,
> > > > > > >
> > > > > > > I have been working on trying to pass the userid and[/color][/color]
> password[color=green][color=darkred]
> > > > > 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[/color]
> > it?[color=darkred]
> > > I
> > > > > > > currently use an XmlTextWriter, Memory Stream and[/color][/color]
> XmlDocument[color=green][color=darkred]
> > > > > objects
> > > > > > > to form the xml parameter. I am trying to complete an[/color]
> > ecommerce[color=darkred]
> > > > > 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.[/color][/color]
> Do[color=green][color=darkred]
> > > you
> > > > > have
> > > > > > > any suggestions? Any help would be appreciated
> > > > > > >
> > > > > > > Precept
> > > > > > >
> > > > > > > ThyRock wrote:
> > > > > > > > Bruce,
> > > > > > > > Again, thanks very much for your help, I have work out[/color][/color]
> this[color=green][color=darkred]
> > > > > problem.
> > > > > > > >
> > > > > > > >
> > > > > > > > "ThyRock" wrote:
> > > > > > > >
> > > > > > > > > I am working on a WebRequest accessing the US Postal
> > > Service
> > > > > > > WebTools test API.
> > > > > > > > > This service uses a DLL file (ShippingAPITest.dll) with[/color][/color]
> a[color=green][color=darkred]
> > > 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[/color]
> > the[color=darkred]
> > > > > > > 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>[/color]
> > <Pounds>10</Pounds>[color=darkred]
> > > > > > > <Ounces>5</Ounces>
> > > > > > > > > <Container>Flat Rate Box</Container>
> > > > > > > > > <Size>REGULAR</Size></Package></RateV2Request>
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I can use this url and query string from the location[/color][/color]
> bar[color=green][color=darkred]
> > > of
> > > > > the
> > > > > > > web
> > > > > > > > > browser and it will return the correct xml response.[/color][/color]
> If[color=green][color=darkred]
> > > this
> > > > > query
> > > > > > > string is
> > > > > > > > > encoded, the DLL will return an error. The USPS DLL is[/color]
> > not[color=darkred]
> > > > > > > decoding an
> > > > > > > > > encoded query string. The USPS is not up to date with[/color]
> > the[color=darkred]
> > > > > latest
> > > > > > > Xml
> > > > > > > > > technology and uses the DLL to retreive the query[/color][/color]
> string[color=green][color=darkred]
> > > 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.
> > > > > > >
> > > > > > >
> > > > >
> > > > >[/color][/color]
>
>[/color]
William Lanza
Guest
 
Posts: n/a
#13: Nov 19 '05

re: WebRequest method usage




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

*** Sent via Developersdex http://www.developersdex.com ***
Closed Thread