I'm trying to send Japanese characters in the headers but getting the error Invalid character in header content
.
I'm using Axios to make the HTTP call and this is what the request configuration looks like:
let request = {
url: 'http://x.x.x.x:3003/resource/path',
method: 'GET',
headers: {
'Content-Type': 'application/json',
'header1': '星'
},
params: {
'星': '星',
}
}
Response: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["header1"]
I found this post which I think is very similar to what I'm trying to achieve here, but the solution proposed is limited to Authorization
only. In my use-case, I can have Japanese characters in both key and value. Consider them as custom headers for which we don't have any prefined key or value.
I tried to pass application/json; charset=utf-8
as the value for Content-Type
but that also didn't work. I also tried encoding the value with encodedURIComponent
but the server received the header as header1: '%E6%98%9F'
. Decoding the received header at the server's end would solve the issue but unfortunately, a fix like this is beyond my reach.
I'm facing this issue in the case of headers only. Surprisingly, params
are getting passed correctly. I tried to find the reason behind this and stumbled upon this document. The note NOTE: Express automatically decodes the values in req.params (using decodeURIComponent). distinctly mentions express decoding the received encoded params. Why isn't there such an option for headers as well?
Can anyone guide me in the right direction? If what I'm trying to achieve is not possible then what other alternatives do I have?
Cheers!