o2geao 发表于 2017-1-12 08:58:15

org.apache.commons.httpclient的jar包的使用

  1.创建HttpClient实例
   HttpClient client = new HttpClient();


2.创建某种连接方法的实例(post或get)
    PostMethod postMethod = new PostMethod(url);
    // 填入各个表单域的值
    NameValuePair[] data = { new NameValuePair("name", "root"), new NameValuePair("password","pwd")};

    // 将表单的值放入postMethod中
    postMethod.setRequestBody(data);

   // 执行postMethod
    int statusCode = httpClient.executeMethod(postMethod);

   //读取内容
    byte[] responseBody = postMethod.getResponseBody();

   //转换

    collectionResult = new String(responseBody);

    System.out.println("返回值为:"+collectionResult);

   //释放链接

   postMethod.releaseConnection();

 
页: [1]
查看完整版本: org.apache.commons.httpclient的jar包的使用