ImportOrg. Apache. commons. httpclient. Cookie;
ImportOrg. Apache. commons. httpclient. httpstate;
ImportOrg. Apache. commons. httpclient. httpclient;
ImportOrg. Apache. commons. httpclient. Methods. getmethod;
Public classGetcookieprintandsetvalue {
Public staticVoidMain (string ARGs [])ThrowsException {
Httpclient client =NewHttpclient ();
Client. getparams (). setparameter ("HTTP. useragent", "my browser ");
Getmethod method =NewGetmethod ("http: // localhost: 8080 /");
Try{
Client.exe cutemethod (method );
Cookie [] cookies = client. getstate (). getcookies ();
For(IntI = 0; I <cookies. length; I ++ ){
Cookie = Cookies [I];
System. Err. println (
"Cookie:" + Cookie. getname () +
", Value:" + Cookie. getvalue () +
", Ispersistent? : "+ Cookie. ispersistent () +
", Expiry date:" + Cookie. getexpirydate () +
", Comment:" + Cookie. getcomment ());
Cookie. setvalue ("My own value ");
}
Client.exe cutemethod (method );
}Catch(Exception e ){
System. Err. println (E );
}Finally{
Method. releaseconnection ();
}
}
}
Cookie. setname ("name ");
Cookie. setvalue ("1111111111 ");