0
我在哪裏可以找到並下載api來實現那段代碼?我用谷歌搜索它,但我找不到它。我發現的唯一一個是:http://hc.apache.org/downloads.cgi但事實並非如此。謝謝。java項目的httpclient api
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();
}
}
}
你試過了什麼版本的雅加達Http客戶端? – dash1e 2012-04-12 17:57:18
此代碼片段使用舊版本的apache庫。 – Carlo 2012-04-12 17:58:42