• 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);
     
  • 相关阅读:
    (紫书,感谢作者)第7章暴力求解法
    明日更新
    明天更新
    UVa11882最大的数(dfs+剪枝)
    UVa12569树上的机器人的规划
    es6中的reduce方法?
    浏览器是如何渲染页面的?
    判断是不是一个数组?
    判断是否是一个数组?
    var与let的区别?
  • 原文地址:https://www.cnblogs.com/stay-sober/p/4615638.html
Copyright © 2020-2023  润新知