2

I am trying to make a GET http request with period in url

ex http://testsite.com/TestEndpoint/Members/first%2Elast%40testemail%2Ecom

in above example first.last@testemail.com is escaped to first%2Elast%40testemail%2Ecom

The problem is HttpClient creates a Uri from the string which unescapes the %2E to . (part of the url turns to first.last%40testmail.com) which causes public API to throw endpoint not found error.

I can make this request from Postman and it works just fine but from .net HttpClient or WebRequest.Create fails.

Is there a way to tell HttpClient not to un-escape the url?

var uri = new Uri("http://testsite.com/TestEndpoint/Members/first%2Elast%40testemail%2Ecom");

I also tried Creating an Uri in .NET automatically urldecodes all parameters from passed string

but that has no effect, not sure if that feature is broken or no longer supported.

Mayank
  • 8,777
  • 4
  • 35
  • 60

1 Answers1

-1

You can try to further "escape" your intended URL with:

client.GetAsync(new Uri("http://testsite.com/testendpoint?members=" + HttpUtility.UrlEncode("first%2Elast%40testemail%2Ecom"));
awais
  • 492
  • 4
  • 17
  • 1
    That will not work as that will cause string to turn into **http://testsite.com/testendpoint/first%252Elast%2540testemail%252Ecom** – Mayank Sep 16 '19 at 19:03
  • You should not pass as an argument the escaped string into UrlEncode, but the actual unescaped string. – MZanetti Sep 17 '19 at 11:05
  • @MZanetti Passing that to the Uri constructor would produce the same problem, because it produces the same string. – Jesse de Wit Sep 18 '19 at 13:03