何时执行HTTPConnection以及它的状态

时间:2016-05-16 21:31:23

标签: java http outputstream httpconnection

我有以下代码从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();

1 个答案:

答案 0 :(得分:3)

当您获得其中一个流或响应代码时,会创建(或从连接池分配)底层TCP连接,或者调用connect()HttpURLConnection对象本身不是TCP连接。