I am looking for a way to accept cookies (all cookies) using HTMLUnit
I am trying to login to my Wordpress website using HTMLUnit, but I cannot submit the form (and therefore cannot enter the system) when the cookies were rejected because my error:
July 14, 2012 10:42:24 org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Cookie rejected:
CODE:
package backend;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Set;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.CookieManager;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.util.Cookie;
public class temp {
WebClient myClient = new WebClient(BrowserVersion.FIREFOX_3);
CookieManager cm = new CookieManager();
HtmlPage page;
public void Someting() throws FailingHttpStatusCodeException, MalformedURLException, IOException{
myClient.setJavaScriptEnabled(false);
myClient.setCssEnabled(false);
myClient.setCookieManager(cm);
page = myClient.getPage("http://nick.wordpress.com/wp-admin");
Set<Cookie> cookies = myClient.getCookieManager().getCookies();
System.out.println("Page status code: " + page.getWebResponse().getStatusCode() + "\nPage status message: " + page.getWebResponse().getStatusMessage());
if(cookies != null)
{
for(Cookie cookie : cookies)
{
this.myClient.getCookieManager().addCookie(cookie);
}
}
System.out.println("We have: " + myClient.getCookieManager().getCookies().size() + " cookie");
}
public static void main(String args[]) throws FailingHttpStatusCodeException, MalformedURLException, IOException{
temp t = new temp();
t.Someting();
}
}
This code excludes the function of filling / submitting the wordpress form, as this does not seem relevant.
When searching the Internet, I could only find 1 or 2 answers on vaugue, where I should change the class "http.client.protocol.ResponseProcessCookies", but I hope that this can be done without this.
, /cookiemanagers, :)