WebRequest方法用法 [英] WebRequest method usage

查看:64
本文介绍了WebRequest方法用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WebRequest访问US Postal Service WebTools测试API。

此服务使用带有查询字符串的DLL文件(ShippingAPITest.dll)

包括XML。

Web服务接受没有url编码的查询字符串。

我必须传递<>它们在查询字符串中的字符。

如果这些字符是url编码的,则服务会拒绝该请求。

此API网址
http://testing.shippingapis.com/ShippingAPITest.dll


它需要一个查询字符串如下:


?API = RateV2& XML =< RateV2Request USERID =" userid" PASSWORD ="密码"> <包

ID =" 0"> <服务> PRIORITY< /服务与GT; < ZipOrigination> 10022< / ZipOrigination>

< ZipDestination> 20008< / ZipDestination> <磅大于10< /磅> <盎司> 5< /盎司>

<容器>固定费率框< / Container>

<尺寸> REGULAR< /尺寸>< /包> < / RateV2Request>

我可以在网页

浏览器的位置栏中使用此网址和查询字符串,它将返回正确的xml响应。如果此查询字符串是
编码,则DLL将返回错误。 USPS DLL不解码

编码的查询字符串。 USPS不是最新的Xml

技术,并使用DLL来检索查询字符串并处理

请求。

我对这个服务提供商的处理非常有限。


有人能告诉我如何在不编码

请求的情况下使用WebRequest方法吗? br />

感谢您的帮助。

解决方案

尝试用逃脱关闭建立uri


string url =

" http://testing.shippingapis.com/ShippingAPITest.dll?API = RateV2& XML =< RateV2R

equest USERID =" userid" PASSWORD ="密码"> <包ID =" 0">

<服务>优先级< /服务>

< ZipOrigination> 10022< / ZipOrigination>< ZipDestination> 20008< ; / ZipDestination>

< Pounds> 10< / Pounds> <盎司> 5< /盎司>

<容器>固定费率框< / Container>

<尺寸> REGULAR< /尺寸>< /包> < / RateV2Request>" ;;


Uri uri = new Uri(url,false);

WebRequest wr = WebRequest.Create(uri);


- 布鲁斯(sqlwork.com)

" ThyRock" <钍***** @ discussions.microsoft.com>在消息中写道

新闻:FA ********************************** @ microsof t.com ...

|我正在使用WebRequest访问美国邮政服务WebTools测试

API。

|此服务使用DLL文件(ShippingAPITest.dll)和查询字符串



|包括XML。

| Web服务接受没有url编码的查询字符串。

|我必须通过<>字符在查询字符串中。

|如果这些字符是url编码,则服务拒绝请求。

|

|

|此API网址是

| http://testing.shippingapis.com/ShippingAPITest.dll

|

|它需要一个查询字符串如下:

|

| ?API = RateV2& XML =< RateV2Request USERID =" userid" PASSWORD =" password">

< Package

| ID = QUOT; 0"> <服务> PRIORITY< /服务与GT; < ZipOrigination> 10022< / ZipOrigination>

| < ZipDestination> 20008< / ZipDestination> <磅< 10< /磅>

<盎司> 5< /盎司>

| < Container> Flat Rate Box< / Container>

| < Size> REGULAR< / Size>< / Package>< / RateV2Request>

|

|

|我可以使用来自网站位置栏的这个网址和查询字符串

|浏览器,它将返回正确的xml响应。如果这个查询字符串



|编码后,DLL将返回错误。 USPS DLL没有解码

|编码查询字符串。 USPS与最新的Xml

|不同技术并使用DLL来检索查询字符串并处理

|请求。

|我对这个服务提供商的处理非常有限。

|

|有人可以告诉我如何在不编码

|的情况下使用WebRequest方法请求?

|

|感谢您的帮助。


Bruce,

非常感谢您的帮助。你的信息非常好。

Uri dontencode参数设置为true确实会创建一个没有编码的uri。


我也有xml态度的问题。态度要求attitube的

值介于双引号之间。使用String或StringBuilder构建xml

字符串时,必须使用内部双引号

上的\字符。

\在字符串中如下:


< RateV2Request USERID = \" userid \" PASSWORD = \" password \">

< Package ID = \" 0 \">


导致错误。需要帮助来构建一个没有

\字符的xml字符串的方法。我将尝试构建一个XmlDocument并将

文档流传递给Uri构造函数。


如果您能提供帮助,请回复。

ThyRock写道:

我正在使用WebRequest访问美国邮政服务WebTools测试API。
此服务使用带有查询字符串的DLL文件(ShippingAPITest.dll)
包括XML。
Web服务接受没有url编码的查询字符串。
我必须传递<>它们在查询字符串中的字符。
如果这些字符是url编码的,则服务拒绝请求。

此API网址
http://testing.shippingapis.com/ShippingAPITest.dll

需要查询字符串如下:

?API = RateV2& XML =< RateV2Request USERID =" userid" PASSWORD ="密码"> <包
ID =" 0"> <服务> PRIORITY< /服务与GT; < ZipOrigination> 10022< / ZipOrigination>
< ZipDestination> 20008< / ZipDestination> <磅大于10< /磅> <盎司> 5< /盎司>
<容器>统一费率箱< /容器>
<尺寸> REGULAR< /尺寸>< /包>< / RateV2Request>

我可以使用来自web浏览器位置栏的这个url和查询字符串,它将返回正确的xml响应。如果此查询字符串已编码,则DLL将返回错误。 USPS DLL不解码
编码的查询字符串。 USPS不是最新的Xml技术,并使用DLL来检索查询字符串并处理
请求。
我对这项服务的处理非常有限提供者。

有人可以告诉我如何在不编码
请求的情况下使用WebRequest方法吗?

感谢您的帮助。



Bruce,

再次,非常感谢你的帮助,我解决了这个问题。

ThyRock写道:

我正在使用WebRequest访问美国邮政服务WebTools测试API。
此服务使用带有查询字符串的DLL文件(ShippingAPITest.dll)
包括XML。
Web服务接受没有url编码的查询字符串。
我必须传递<>它们在查询字符串中的字符。
如果这些字符是url编码的,则服务拒绝请求。

此API网址
http://testing.shippingapis.com/ShippingAPITest.dll

需要查询字符串如下:

?API = RateV2& XML =< RateV2Request USERID =" userid" PASSWORD ="密码"> <包
ID =" 0"> <服务> PRIORITY< /服务与GT; < ZipOrigination> 10022< / ZipOrigination>
< ZipDestination> 20008< / ZipDestination> <磅大于10< /磅> <盎司> 5< /盎司>
<容器>统一费率箱< /容器>
<尺寸> REGULAR< /尺寸>< /包>< / RateV2Request>

我可以使用来自web浏览器位置栏的这个url和查询字符串,它将返回正确的xml响应。如果此查询字符串已编码,则DLL将返回错误。 USPS DLL不解码
编码的查询字符串。 USPS不是最新的Xml技术,并使用DLL来检索查询字符串并处理
请求。
我对这项服务的处理非常有限提供者。

有人可以告诉我如何在不编码
请求的情况下使用WebRequest方法吗?

感谢您的帮助。



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.

解决方案

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" <Th*****@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.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.


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:

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,
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 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.



这篇关于WebRequest方法用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆