我使用 Linux 在 AWS EBS 中设置了一个新服务器,并将该服务器配置为 UTF-8,因为我使用了一些希伯来语文本。
该代码在 Windows 上运行,但当我迁移到 Linux 时,它停止运行了。 代码将 HTTP post 发送到另一台服务器并从中获取 JSON 对象并开始解析,所有希伯来语文本都是这样的:קבוצ×
- 我尝试添加到 AWS 软件配置:JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8
- 我尝试将 JAVA_OPTIONS="-Dfile.encoding=UTF-8"添加到 tomcat8.conf 文件。 (同样尝试使用 JAVA_OPTS)。
我也尝试通过编码添加 catalina 选项。
HttpPost 请求 = new HttpPost(URL); //创建 JSON 并设置 API Token JSONObject SendJson = new JSONObject(); SendJson.put(字段, 键); StringEntity 参数 =new StringEntity(SendJson.toString()); request.setEntity(参数); //设置标题类型 request.addHeader("内容类型", "application/json;charset=UTF-8"); request.addHeader("接受编码", "UTF-8"); //执行并等待响应 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() - 输出 UTF-8
我得到没有希伯来语文本的 JSON :/
部分 JSON 例如: {"item_group_id":1,"item_group_name":"קבוצה×","picture_link":""},
谢谢, 大卫
最佳答案
我修好了。 我将区域设置更改为 he_IL 和 he_IL.UTF8,然后重新启动服务器并且它工作了。
谢谢!
关于java - AWS Elastic Beanstalk 上 HTTP Post 对象的 UTF-8 编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55431203/