简体   繁体   中英

UTF-8 Encoding issue with HTTP Post object on AWS Elastic Beanstalk

I setting up a new server in AWS EBS with linux and configured the server to be UTF-8 because I use some text in Hebrew.

The code works on Windows but when I migrated to Linux this stopped working. The code send HTTP post to another server and get JSON object from it and start to parse, All the Hebrew text is something like this: ק×'וצ×

  1. I tried to add to AWS software configuration : JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8
  2. I tried to add JAVA_OPTIONS="-Dfile.encoding=UTF-8" to tomcat8.conf file. (aslo tried with JAVA_OPTS).
  3. I tried to add catalina options also with encoding.

    HttpPost request = new HttpPost(URL); // Create JSON and set the API Token JSONObject SendJson = new JSONObject(); SendJson.put(field, key); StringEntity params =new StringEntity(SendJson.toString()); request.setEntity(params); // set Header Type request.addHeader("content-type", "application/json;charset=UTF-8"); request.addHeader("Accept-Encoding", "UTF-8"); // Execute and wait for response HttpResponse httpResponse = httpClient.execute(request);

      HttpEntity resEntity = httpResponse.getEntity(); // cast InputStream to String for JSON conversion BufferedReader reader = new BufferedReader(new InputStreamReader( resEntity.getContent())); //String strInputStream = EntityUtils.toString(resEntity,"UTF-8"); String strInputStream = reader.readLine(); //debug System.out.println("David Encoding problem"); System.out.println(Charset.defaultCharset().name()); System.out.println(strInputStream); JSONObject answerObj = new JSONObject(strInputStream); 

Charset.defaultCharset().name() - output UTF-8

I get JSON with no Hebrew text :/

part of the JSON for example: {"item_group_id":1,"item_group_name":"ק×'וצה ×","picture_link":""},

Thanks, David

I fixed it. I changed the locale to he_IL and he_IL.UTF8, then restarted the server and it worked.

Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM