2014-02-06 92 views
0

我在調用由我的.NET應用程序提供的與字符編碼相關的REST Web服務時遇到問題。調用.NET Rest Web服務拋出錯誤請求

我送的東西是這樣的:

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

查詢字符串是這個,它的URL編碼,由於%2B(+)字符我得到一個錯誤的請求 - 無效的URL錯誤。

如果未指定此字符,則Web Service將成功響應。

我在做什麼錯?

感謝

+0

那麼如果你URL編碼的%字符呢? –

+0

你是什麼意思?如果我編碼%字符,我會得到類似%252B的東西嗎? – RedEagle

回答

0

問題不是%2B字符,而是數據被解析的格式。

不正確: HTTP://:/DotNetApplication/RestService.svc/eyJudW1iZXIiOiI5NDU5NjA5M%2BDAiLCJtc2ciOiJQYXJhIGNvbmZpcm1hciBhIHJlY

正確(查詢字符串) HTTP://:/DotNetApplication/RestService.svc/請求= eyJudW1iZXIiOiI5NDU5NjA5M%2BDAiLCJtc2ciOiJQYXJhIGNvbmZpcm1hciBhIHJlY

因爲數據正在通過的路徑結構,而不是標準的查詢字符串傳遞給REST Web服務,字符的限爲254

謝謝

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. 
+0

已將其更改爲http://:/DotNetApplication/RestService.svc/eyJudW1iZXIiOiI5NDU5NjA5M%252BDAiLCJtc2ciOiJQYXJhIGNvbmZpcm1hciBhIHJlY,問題仍然存在 – RedEagle

0

這似乎不是%2B問題,而是字符大小。我使用get,但URL長度大約爲350個字符。