Wo kann ich die API finden und herunterladen, um dieses Stück Code zu implementieren? Ich habe es mit Google gesucht, aber ich kann es nicht finden. Der einzige, den ich gefunden habe, ist: http://hc.apache.org/downloads.cgi, aber das ist es nicht. Vielen Dank.httpclient api für Java-Projekt
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();
}
}
}
Welche Version von Jakarta Http Client haben Sie versucht? – dash1e
Dieses Code-Snippet verwendet eine alte Version der Apache-Bibliotheken. – Carlo