java - 响应 SOAP 请求的 UTF-8 问题
问题描述
当我从 SOAP UI 发出 SOAP 请求时,它会返回正常的答案,但是当我从 Java 代码中尝试时,它会返回无法理解的字符。我试图将答案转换为 UTF8 格式,但没有帮助。请提出解决方案,我的 SOAP 请求可能有问题。响应示例:OÄžLU,但必须是OĞLU或MÄ°KAYIL而不是MİKAYIL
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
String userCredentials = username + ":" + password;
String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userCredentials.getBytes()));
con.setRequestProperty("Authorization", basicAuth);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "text/xml");
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(myXML);
wr.flush();
wr.close();
String responseStatus = con.getResponseMessage();
System.out.println(responseStatus);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
String xmlResponse = response.toString();
我试过了:
ByteBuffer buffer = ByteBuffer.wrap(xmlResponse.getBytes("UTF-8"));
String converted = new String(buffer.array(), "UTF-8");
解决方案
尝试这个:
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
推荐阅读
- windows-server - 删除 Server 2016 上的“Windows Server”固定应用
- xcode - 无法获得源代码的真实路径 - Xcode、SFML、C++
- ios - 更改签名证书后重新启动 App Store 上的现有 iOS 应用程序?
- c - 为什么会出现分段错误 11(使用 fgets 读取输入并存储在数组中)?
- python - 在服务器而不是本地机器上处理 MemoryError
- r - 使用 dplyr 如何将分组数据除以与之关联的特定值
- apache-flink - Apache Flink:架构问题:背压和处理故障模式
- perl - 如何在 Perl 中一个一个地 gzip 几个文件
- java - 在 stage.show() 之后将子项添加到窗格
- automated-tests - 赛普拉斯 - 让 1 个测试调用另一个测试并运行它