简体   繁体   中英

Is there a way to send escaped period character in Uri for HttpClient

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.

您可以尝试通过以下方法进一步“转义”您的预期URL:

client.GetAsync(new Uri("http://testsite.com/testendpoint?members=" + HttpUtility.UrlEncode("first%2Elast%40testemail%2Ecom"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM