I am making a call from a node middle-tier to a Java backend and passing a string as a query param. Everything works great until non-English alphabet character are used (ex: ř,ý). When Java receives these characters it throws:
parse exception: org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8!
This call works perfectly:
GET http://localhost:8000/server/name?name=smith
This call fails with the above error:
GET http://localhost:8000/server/name?name=sořovský
My question involves where to address this issue. I have found this utf8 encoder for node and was thinking about encoding my strings as utf8 before calling my Java layer in the future. Is that the correct approach or should I be doing something within Java?
Note, this is what my relevant request headers look like:
{
...
accept: 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, sdch',
'accept-language': 'en-US,en;q=0.8,el;q=0.6',
...
}
Save your javascript file to utf8.
var name = "sořovský",
param1 = encodeURIComponent(name);
var url = "http://localhost:8000/server/name?name=" + param1;
console.log(url);
// http://localhost:8000/server/name?name=so%C5%99ovsk%C3%BD
You can see the log with GET http://localhost:8000/server/name?name=sořovský
:
{
"args": {
"name": "sořovský"
},
"headers": {
"Accept": "application/json, text/plain, */*",
"Accept-encoding": "gzip, deflate, sdch",
"Accept-language": "en-US,en;q=0.8,el;q=0.6",
//...
},
"url": "http://localhost:8000/server/name?name=sořovský"
}
GET only supports the ASCII char.set to send other characters you need to percent encode the special chars.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With