Java UTF-8 encoding not working HttpURLConnection
I tried to do post call and to pass input with this value -
"ä愛لآहที่" I got error message
{"error":{"code":"","message":{"lang":"en-US","value":{"type":"ODataInputError","message":"Bad
Input: Invalid JSON format"}}}}
This is my code
conn.setRequestMethod(ConnectionMethod.POST.toString());
conn.setRequestProperty(CONTENT_LENGTH,
Integer.toString(content.getBytes().length));
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(content);
wr.flush();
wr.close();
InputStream resultContentIS;
String resultContent;
try {
resultContentIS = conn.getInputStream();
it falied on conn.getInputStream();
The value of content is
{ "input" : "ä愛لآहที่" }
It is working where the input is String or integer
No comments:
Post a Comment