Reputation: 717
Where can i find and download the api to implement that piece of code? I searched it with google but i can't find it. The only one i found is this: http://hc.apache.org/downloads.cgi but it's not that. Thank you.
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();
}
}
}
Upvotes: 0
Views: 656
Reputation: 54312
According to the project page:
The Commons HttpClient project is now end of life, and is no longer being developed. It has been replaced by the Apache HttpComponents project in its HttpClient and HttpCore modules, which offer better performance and more flexibility.
So, you probably do want that page.
If you want an older version, like 3.0, you can find it in the archives.
Also, I highly recommend learning to use Maven, since it will make handling dependencies in projects much easier.
Upvotes: 5