zoukankan      html  css  js  c++  java
  • httpClient 3

    HttpClient httpClient = new HttpClient();

      HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams();
      // 设置连接超时时间(单位毫秒)
      managerParams.setConnectionTimeout(30000);
      // 设置读数据超时时间(单位毫秒)
      managerParams.setSoTimeout(120000);
      String url = "localhost";
      PostMethod postMethod = new PostMethod(url);
      Header  header = new Header();
      header.setName("Cookie");
      header.setValue("cookie");
      header.setName("Refer");
      header.setValue("refer");
      postMethod.setRequestHeader(header);
      String strResponse = null;
      int statusCode=-1;
      try
      {
        statusCode= httpClient.executeMethod(postMethod);
        if (statusCode != HttpStatus.SC_OK)
        {
          throw new IllegalStateException("Method failed: "+ postMethod.getStatusLine());
        }
        strResponse = postMethod.getResponseBodyAsString();
      } catch (Exception ex)
      {
        throw new IllegalStateException(ex.toString());
      }
        finally
      {
         //释放连接
         postMethod.releaseConnection();
      }
        System.out.println(strResponse);
     
  • 相关阅读:
    2.6
    zuoye
    练习1
    练习
    练习
    4
    3
    2
    1
    1.3
  • 原文地址:https://www.cnblogs.com/stay-sober/p/4615638.html
Copyright © 2011-2022 走看看