我有下面的代码,它从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();
当您获得其中一个流或响应代码或调用connect()
时,将创建(或从连接池中分配)底层TCP连接。HttpURLConnection
对象本身不是TCP连接。