Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Unicode characters in HTTP headers?

Tags:

http

protocols

Is HTTP headers limited to US-ASCII charset?

Can I use unicode characters in HTTP headers?

Edit:

I want to do like this:

WebClient myWebClient = new WebClient();
myWebClient.Headers.Add("Content-Type","یونیکد");
like image 364
Amir Saniyan Avatar asked Sep 27 '11 09:09

Amir Saniyan


People also ask

Can HTTP headers have special characters?

The value of the HTTP request header you want to set can only contain: Alphanumeric characters: a - z and A - Z. The following special characters: _ :;.,\/"'?!(){}[]@<>=-+*#$&`|~^%

Can HTTP headers have non ascii characters?

RFC 2616 is saying that you can ONLY use US-ASCII in HTTP headers. Other characters have to be encoded.

How do I set character encoding in HTTP header?

Use the header() function before generating any content, e.g.: header('Content-type: text/html; charset=utf-8'); Java Servlets.

What encoding do HTTP headers use?

HTTP messages are encoded with ISO-8859-1 (which can be nominally considered as an enhanced ASCII version, containing umlauts, diacritic and other characters of West European languages). At the same time, the message body can use another encoding assigned in "Content-Type" header.


1 Answers

First of all, the header field in your example does not allow what you want; media type names are ASCII.

In theory, HTTP header field values can transport anything; the tricky part is to get all parties (sender, receiver, and intermediates) to agree on the encoding.

Thus, the safe way to do this is to stick to ASCII, and choose an encoding on top of that, such as the one defined in RFC 5987.

like image 167
Julian Reschke Avatar answered Oct 01 '22 15:10

Julian Reschke