2

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/abc) it send the Uri as it is but it fails as server side it is converted to (abcd.com/xyz/pqr%2Fss/abc)

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
avaya
  • 21
  • 1
  • 2
  • If it sends the URL "as is" as per your second example, it fails on the server. So yes, there is a way to do that -- the double-encoding method. – cdhowie Nov 17 '10 at 17:12
  • Then you have an issue with the server. What's the server-side? – SLaks Nov 17 '10 at 17:12
  • And you have tried using this HTMLEncode on the string before sending it over? http://msdn.microsoft.com/en-us/library/w3te6wfz.aspx – Mike Cheel Nov 17 '10 at 17:44
  • Here is answer: http://stackoverflow.com/questions/781205/c-net-getting-a-url-with-an-url-encoded-slash – Maer007 Aug 13 '11 at 13:59
  • Here is answer http://stackoverflow.com/questions/781205/c-net-getting-a-url-with-an-url-encoded-slash – Maer007 Aug 13 '11 at 14:01

2 Answers2

0

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
WiseGuyEh
  • 18,584
  • 1
  • 20
  • 20
0

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")

Mat
  • 202,337
  • 40
  • 393
  • 406