调用.NET Rest Web服务会抛出错误的请求

时间:2014-02-06 13:16:20

标签: .net rest

我在调用我的.NET应用程序提供的与Web编码有关的REST Web服务时遇到问题。

我发送的内容如下:

的http://:/DotNetApplication/RestService.svc/的 eyJudW1iZXIiOiI5NDU5NjA5M%2BDAiLCJtc2ciOiJQYXJhIGNvbmZpcm1hciBhIHJlY

查询字符串是这一个,它的网址是编码的,因为%2B(+)字符我收到 错误请求 - 无效网址 错误。

如果未指定此字符,则Web Service会成功响应。

我做错了什么?

由于

3 个答案:

答案 0 :(得分:0)

请尝试对%个字符进行编码,它自己生成的事件为%

根据RFC 2396, page 9

Because the percent "%" character always has the reserved purpose of
being the escape indicator, it must be escaped as "%25" in order to
be used as data within a URI.  Implementers should be careful not to
escape or unescape the same string more than once, since unescaping
an already unescaped string might lead to misinterpreting a percent
data character as another escaped character, or vice versa in the
case of escaping an already escaped string.

答案 1 :(得分:0)

似乎不是%2b问题,而是字符大小。我正在使用get,但URL大约有350个字符。

答案 2 :(得分:0)

问题不是%2B字符,而是数据被解析的格式。

<强>不正确: HTTP://:/DotNetApplication/RestService.svc/eyJudW1iZXIiOiI5NDU5NjA5M%2BDAiLCJtc2ciOiJQYXJhIGNvbmZpcm1hciBhIHJlY

更正(查询字符串) HTTP://:/DotNetApplication/RestService.svc/请求= eyJudW1iZXIiOiI5NDU5NjA5M%2BDAiLCJtc2ciOiJQYXJhIGNvbmZpcm1hciBhIHJlY

由于数据是通过路径结构而不是标准查询字符串传递给REST Web服务的,因此字符数限制为254.

由于