views:

325

answers:

2

Having a problem with HttpWebRequest decoding my encoded URL.

var requestUrl = "https://www.google.com/webmasters/tools/feeds/http%3A%2F%2Fwww%2example%2Ecom%2F/crawlissues/";   
var request = (HttpWebRequest)WebRequest.Create(requestUrl);

When looking at end request URL is becomes:

https://www.google.com/webmasters/tools/feeds/http://www.example.com//crawlissues/

Which of course returns a 400 Bad request. I am guessing it is something todo with the URI class rather than HttpWebRequest. How do I stop this from happening?

A: 

Not sure but may be HttpServerUtility.UrlEncode method will help.

Upd. Alternatively you may use WebClient class.

sashaeve
Thanks but the url is already encoded, the problem is that something is decoding it.
Gareth Brown
I have tried the WebClient class and it makes no difference.
Gareth Brown
A: 

Apparently the Uri decodes it in parts. I don't know who's right or wrong here, but see this duplicate question that describes a hack to bypass it:

http://stackoverflow.com/questions/781205/c-net-getting-a-url-with-an-url-encoded-slash

Korbinian