gpt4 book ai didi

java - http 客户端 -> 发送的消息包含一个 & 符号

转载 作者:可可西里 更新时间:2023-11-01 16:22:29 25 4
gpt4 key购买 nike

也许这里有人可以帮助我...

我写了一个非常简单的 java http 客户端,它将 xml 作为发布数据发送到网络服务器。现在奇怪的是,我们的客户报告说在 postdata 中有一个尾随的 & 号。如果您查看源代码,我完全不知道那是怎么回事,我在源代码中删除了每个变量...

public static void main(String[] args) {
try {
final URL httpURL = new URL(args[0]);

String request = "<root/>";

HttpURLConnection connection = (HttpURLConnection)httpURL.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);

OutputStream os = connection.getOutputStream();
os.write(request.getBytes());
os.close();

BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String tmp;
String xml = new String();
while ((tmp = in.readLine()) != null) {
xml = xml.concat(tmp);
}
connection.getInputStream().close();
connection.disconnect();
System.out.println("Result: " + xml);
} catch (Exception e) {
System.err.println("Exception ocurred " + e);
}
}

如您所见,目前我们发送的是一个固定的“xml”,它只是一个标签。

有谁知道是否存在已知错误或场景,类似的事情会发生在什么地方?

我感谢每一个帮助:)。谢谢!

最佳答案

我在您的代码中看不到任何会导致将 & 符号发送到服务器的问题。我怀疑问题可能出在服务器端。

尝试使用 wireshark 或类似的东西来捕获发送到服务器的 TCP 数据包,看看您是否可以在那里看到杂散字符。

关于java - http 客户端 -> 发送的消息包含一个 & 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3440460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com