我下面的代码从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连接。
关于java - 执行HTTPConnection时,它的状态是什么,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37263577/