Reputation: 337
I'm building a react
application and I use Node
(with Express) as a proxy-server. I send data from react app to node-express, then in Node I use that data to form URI and to make requests to another server.
My question is this: Shouldn't 'content-type': 'charset: utf-8'
be enough when I send data including greek characters to Node? For example, I make a post request (using Fetch) to Node and I send code 'ΠΕ0001' using the header I already mentioned. Why do I get the error 'Path contains unescaped characters'? When I use encodeURIComponent
it does work, but why 'charset: utf-8' is not enough?
Upvotes: 1
Views: 771
Reputation: 357
Just setting the header 'content-type': 'charset: utf-8'
is not enough. Essentially with this Header you're just telling the server (Node in this instance), that the data you send is in utf-8
format, which it should expect anyway.
Your string, however, is in UTF-16 format, because the letter Π
needs two bytes to be represented..
You can read more about character encoding here.
Hence you need encodeURIComponent
first. In our case, Π
is then represented as %CE%A0
, which are its byte's representations in UTF-8.
Upvotes: 2
Reputation: 109
Upvotes: 0