0

I am writing my program in C# .NET and I am trying to get my HttpClient to send a GET request exactly how the string is declared. No matter what I do, the GET request url is always changing.

For example,

client.GetAsync("http://example.com/?id=123%34");
// returns GET http://example.com?id=1234 (before it reaches the server)

or

client.GetAsync(new Uri("http://example.com/?id=123%34"));
// also returns GET http://example.com?id=1234 (before it reaches the server)
// I need the server to see http://example.com?id=123%34 before it reaches
// the server so it can convert the value 4 on the server side.

is making a request to "http://www.example.com/?id=1234". Which is not what I am hoping to achieve. I understand that %34 is the same as sending 4, but I need the webserver to see that %34 is incoming. I want the webserver to handle the percent encoding conversion.

Is there anyway to tell HttpClient to stop encoding/changing the GET request url? I was thinking about overloading the GetAsync() method but I honestly do not know where to begin.

I determined the problem by plugging my program into BURP and Fiddler. HttpClient is encoding my url before it reaches the server.

C O
  • 45
  • 10
  • 1
    Do you mean `123%2534` maybe? – dxiv Aug 26 '16 at 04:20
  • Unfortunately not, the server would see it as a percent sign when it comes in. I need the server to convert the value %34 into 4. The problem is HttpClient is converting the value BEFORE it reaches the server. Maybe my next step would be getting HttpClient to convert 4 to %34 before it sends? I'm not sure how to do that. – C O Aug 26 '16 at 04:23
  • Can you please detail how you determined that the `%34` was getting converted BEFORE it hit your server, rather that the query string being "url decoded" on receipt? I also don't understand what you want. In your question you state: "I understand that %34 is the same as sending 4, but I need the webserver to see that %34". Is your server expecting to receive the value `4` or `%34`? – Brendan Green Aug 26 '16 at 04:25
  • `Unfortunately not, the server would see it as a percent sign when it comes in` Not sure how this rhymes with the original question `I need the webserver to see that %34 is incoming`. The server could either see *or* not see the `%` sign - but not both. – dxiv Aug 26 '16 at 04:26
  • I used Fiddler and BURP, it is indeed converting the value BEFORE it reaches the server. The server would see it as "%" + 34, it would not convert "%34" to the value '4'. I want the server to see "%34" come in so it can convert that value to 4. The way that was suggested earlier the server would see the percent as an actual percent symbol and not for percent encoding. – C O Aug 26 '16 at 04:27
  • May be it is Fiddler which is displaying it as decoded. There are also security measures to remove encoding for not required characters to make log analysis easy. – Akash Kava Aug 26 '16 at 07:18
  • I fixed it. I used the "dontEscape: true" parameter inside Uri(); It's obsolete but it worked as a temporary solution. – C O Aug 26 '16 at 07:30
  • Refer to this article here, http://stackoverflow.com/questions/36134403/why-is-system-net-http-httpclient-encoding-my-request-url – C O Aug 26 '16 at 07:30

0 Answers0