GAE and HtmlUnit 2.9 - getting exception upon jsxGet_cookie
I'm trying to login to google using HtmlUnit in an app in GAE. However, I keep getting this error:
Exception invoking jsxGet_cookie
Which is because
Caused by: java.lang.IllegalArgumentException: Invalid port: -1
at org.apache.http.cookie.CookieOrigin.<init>(CookieOrigin.java:58)
at com.gargoylesoftware.htmlunit.CookieManager.getCookies(CookieManager.java:127)
at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.jsxGet_cookie(HTMLDocument.java:638)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:172)
... 94 more
This occurs 开发者_如何学Cwhen running in GAE and in my computer.
Has anybody ever seen this kind of error before? How can I change the default Port? Are there any workarounds?
Change the URL you are fetching to include the default port 80. Example: http://www.cnn.com
becomes http://www.cnn.com:80
. There's also a workaround involving overriding classes but I prefer to clarify the URL.
I had that problem at first (I have a GWT+GAE app) and I was using this very simple code and I got the js cookie exception and the port:-1 exception
WebClient webClient = Holder.get();
HtmlPage page=null;
try {
page = webClient.getPage(url);
System.out.println("CRAWLER DONE");
} catch (FailingHttpStatusCodeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// appengine hack because it's single threaded
String pageContent = page.asXml();
webClient.closeAllWindows();
return pageContent;
then I tried the following,
webClient.setCssEnabled(false);
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(false);
And it just miracusly worked. cheers.
精彩评论