用于java项目的httpclient api

Mar*_*eli 0 java http

我在哪里可以找到并下载api来实现那段代码?我用谷歌搜索它,但我找不到它.我发现的唯一一个是:http://hc.apache.org/downloads.cgi 但不是那样的.谢谢.

import org.apache.commons.httpclient.Cookie;  
import org.apache.commons.httpclient.HttpState;  
import org.apache.commons.httpclient.HttpClient;  
import org.apache.commons.httpclient.methods.GetMethod;  

public class GetCookiePrintAndSetValue {  

  public static void main(String args[]) throws Exception {  

    HttpClient client = new HttpClient();  
    client.getParams().setParameter("j_username", "abc");  
    client.getParams().setParameter("j_password", "pqr");  

    GetMethod method = new GetMethod("http://localhost:8080/");  
    try{  
      client.executeMethod(method);  
      Cookie[] cookies = client.getState().getCookies();  
      for (int i = 0; i < cookies.length; i++) {  
        Cookie cookie = cookies[i];  
        System.err.println(  
          "Cookie: " + cookie.getName() +  
          ", Value: " + cookie.getValue() +  
          ", IsPersistent?: " + cookie.isPersistent() +  
          ", Expiry Date: " + cookie.getExpiryDate() +  
          ", Comment: " + cookie.getComment());  
        }  
      client.executeMethod(method);  
    } catch(Exception e) {  
      System.err.println(e);  
    } finally {  
      method.releaseConnection();  
    }  
  }  
}  
Run Code Online (Sandbox Code Playgroud)

Rei*_*ica 5

根据项目页面:

Commons HttpClient项目现已结束,现已不再开发.它已被HttpClient和HttpCore模块中的Apache HttpComponents项目取代,它提供了更好的性能和更大的灵活性.

所以,你可能想要那个页面.

如果你想要一个旧的版本,比如3.0,你可以在档案中找到它.

此外,我强烈建议学习使用Maven,因为它将使项目中的处理依赖性变得更加容易.