4

Does the HttpWebRequest class automatically encode URL parameter? I have created a HttpWebRequest with URL "http://test.com/124?param=%2Ea". When I capture a fiddler trace, I see the HTTP get request becomes "http://test.com/124?param=.a" i.e. "%2E" becomes ".".

I have tried setting up debugger in my code and I am sure the url I passed in HttpWebRequest is "http://test.com/124?param=%2Ea" Do you know if HttpWebRequest does that automatically? And how can I disable it?

n179911
  • 19,547
  • 46
  • 120
  • 162
  • Cannot reproduce that, if I make request with %2E I see that in fiddler and if I just use "." I also see that. Anyway "." is allowed in url so if your backend decodes the url-parameter it should not matter if you use "." or %2E. What is your problem in general? – Esko Oct 17 '16 at 06:25

1 Answers1

0

The problem seems to be that, although %2e is the url encoded equivalent of ., you want the request url to remain the exact same way you typed it, right?

It seems Uri does not allow for escaped slashes / or dots .. Apparently this is for backward compatibility purposes. You can try the workaround mentioned on this SO answer which is backed by a solution by MS themselves on this bug report on MS Connect

They suggest placing the following code in your app.config or web.config file:

<uri> 
    <schemeSettings> 
        <add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes" /> 
    </schemeSettings> 
</uri>
Community
  • 1
  • 1
fmello
  • 563
  • 2
  • 9