我有以下代码从HttpURLConnection
生成OutputStream
实际执行连接时,如何检查其状态?
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("PUT");
httpCon.addRequestProperty("X-Auth-Token", getAuthToken());
httpCon.setDoInput(true);
httpCon.setRequestProperty("Connection", "close");
httpCon.setReadTimeout(READ_TIMEOUT);
httpCon.setRequestProperty("Transfer-Encoding","chunked");
httpCon.setDoOutput(true);
httpCon.setChunkedStreamingMode(STREAMING_CHUNK);
mOutputStream = httpCon.getOutputStream();
答案 0 :(得分:3)
当您获得其中一个流或响应代码时,会创建(或从连接池分配)底层TCP连接,或者调用connect()
。 HttpURLConnection
对象本身不是TCP连接。