【发布时间】:2023-04-09 05:43:02
【问题描述】:
我正在尝试从 APP Engine 端点发送 HTTP 请求,从 Postman 的实验中我知道结果很大,并且请求通常需要大约一分钟。
这是我的代码:
void testRequest() {
String test = getConnectionString();
URL url = new URL(YARDI_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/xml");
connection.setConnectTimeout(1000000);
OutputStream os = connection.getOutputStream();
PrintWriter p = new PrintWriter(os);
p.print(test);
p.close();
YardiResponse response = new
YardiResponse(connection.getInputStream().toString());
System.out.println(response.getResponse());
connection.disconnect();
}
我遇到两个错误,
第一个是:java.net.ProtocolException: Cannot write output after reading input.
很长一段时间后,我收到了java.net.SocketException: Connection reset 消息。
很明显,我对 Steam 以及我发送它们的方式处理不当。
【问题讨论】:
标签: java http inputstream outputstream