0

I have a url with the pipe | symbol. When I call it from Httpclient it is getting encoded to %7C.

I read there was a 'dont escape' on the Uri in .NET but that has now been marked obsolete.

Is there anything I can do so that this | is not encoded on the request?

The url I am building is like:

HttpRequestMessage requestMessage = _httpClient.PrepareRequestMessage($"your/notstandardquerystringparam:term|otherterm", HttpMethod.Get, null, null);
var response = await _httpClient.SendAsync(requestMessage);

The service I am calling is failing when the | symbol is getting encoded. I need it passed to the service as the actual | symbol

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Ctrl_Alt_Defeat
  • 3,933
  • 12
  • 66
  • 116

1 Answers1

0

Maybe this is an interesting post that might help: URL Encoding using C#

Personally, I am using a library like RestSharp to do this.

I am not sure where that pipe needs to be. In the URL segment or query? I assume the query parameters in the following example since that is the only place where I could imagine you need a pipe.

using var client = new RestClient("https://example.com/api");

var request = new RestRequest("your/endpoint");

// the last parameter encode=false will disable encoding
request.AddQueryParameter("queryname", "term|otherterm", false); 

var response = await client.GetAsync(request);

// GET https://example.com/api/your/endpoint?queryname=term|otherterm
hwcverwe
  • 5,287
  • 7
  • 35
  • 63