【发布时间】:2019-12-29 04:05:36
【问题描述】:
我的代码发送 HttpConnection,然后尝试使用 connection.getInputStream() 或 connection.getErrorStream() 反序列化响应。
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); // getErrorStream()
String content = in.lines().collect(Collectors.joining());
如何将连接传递给parse(HttpURLConnection connection) 函数并在完成后调用connection.disconnect()?
我在想
connection.disconnect();
return MyObject.fromString(connection.getInputStream(), connection.getErrorStream());
但不确定在阅读响应之前断开连接是否有意义。
【问题讨论】:
标签: java httprequest httpurlconnection nshttpurlresponse