开发者

C# decodes URL containing %2F on path, is there any way to instruct API to send the URL as it is?

I am having a URL in below format abcd.com/xyz/pqr%2Fss/abc

I want this to be send to server as it is. When I build Uri using System.Uri it converts it to abcd.com/xyz/pqr/ss/abc and it fails as I don't have a URL with the specified path.

When I tried with double encoding (abcd.com/xyz/pqr%252Fss/开发者_如何学Pythonabc) it send the Uri as it is but it fails as server side it is converted to (abcd.com/xyz/pqr%2Fss/abc)


If you construct your uri as such:

Uri u = new Uri("http://abcd.com/xyz/pqr%2Fss/abc")

Access the encoded string like this:

u.OriginalString


I had this problem too, but I found the solution: when you use HttpUtility.UrlEncode to be sure that the application will read the url right you have to construct the link this way:

http://www.abcd.com/xyz?val=pqr%2Fss

and not like this

http://www.abcd.com/xyz/pqr%2Fss

where pqr%2Fss is the result of the HttpUtility.UrlEncode("SOME STRING")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜