1

I am using HTTP headers to send a string which contains Unicode characters (such as ñ) to a custom http server.

When I add the string as a header:

webClient.Headers.Add("Custom-Data", "señor");

It is interpreted by the server as:

se�or

Obviously I need to encode the value differently, but I am unsure what encoding to use.

How should I encode this HTTP header to preserve extended/special characters?

Community
  • 1
  • 1
JYelton
  • 35,664
  • 27
  • 132
  • 191

1 Answers1

2

As @Jordan suggested, representing the string as base64 (with UTF8 encoding) worked well:

On the client side:

webClient.Headers.Add("Custom-Data",
    Convert.ToBase64String(Encoding.UTF8.GetBytes("señor")));

And on the server:

string customData = Encoding.UTF8.GetString(Convert.FromBase64String(customHeader.Value));
JYelton
  • 35,664
  • 27
  • 132
  • 191