我正在尝试使用 WWW::Scripter 模块登录到 Java 网站。使用 WWW::Mechanize 模块可以正常工作,但是一旦通过身份验证,该站点就有我需要调用的 JavaScript 函数 - 因此需要 Scripter。
经过大量的故障排除后,我发现从 click() 事件发送的数据包的差异是 Content-Type varaibale。
Mechanize 有: Content-Type: application/x-www-form-urlencoded\r\n 但 Scripter 有: Content-Type: application/x-www-form-urlencoded; charset="ISO-8859-1"\r\n(这是使用WireShark查看的)
这解释了我从网站收到的错误:
错误消息:“ISO-8859-1”错误堆栈跟踪:java.nio.charset.IllegalCharsetNameException:“ISO-8859-1”在 java.nio.charset.Charset.checkName(Charset.java:305) 在 java.nio .charset.Charset.lookup(Charset.java:439) at java.nio.charset.Charset.forName(Charset.java(Inlined Compiled Code))
at java.lang.StringCoding$DecoderCache.makeDecoder(StringCoding.java(Com
堆代码))在 java.lang.StringCoding$1.run(StringCoding.java(编译代码))在 java.security.AccessController.doPrivileged1(本机方法)在 java.security.AccessController.doPrivileged(AccessController.java(编译代码) )) 在 java.lang.StringCoding$DecoderCache.getDecoder(StringCoding.java(Comp iled Code)) 在 java.lang.StringCoding.getDecoder(StringCoding.java(Inlined Compiled Code)) 在 java.lang.StringCoding.decode(StringCoding .java(Compiled Code)) at java.lang.String.(String.java(Compiled Code)) at java.lang.String.(String.java(Inlined Compiled Code)) at com.ibm.ws.webcontainer.servlet .RequestUtils.parsePostData(RequestUti ls.java(Compiled Code)) 在 com.ibm.ws.webcontainer.srt.SRTServletRequest.parseParameters(SRTServ letRequest.java(Compiled Code)) at com.ibm.ws.webcontainer.srt.SRTServletRequest.getParameterNames(SRTSe rvletRequest.java(Compiled Code)) at javax.servlet.ServletRequestWrapper.getParameterNames(ServletRequestW rapper.java(Compiled Code)) at org .apache.struts.util.RequestUtils.populate(RequestUtils.java(Compiled Code)) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProc essor.java(Compiled Code)) at org.apache.struts.action .RequestProcessor.process(RequestProcessor.java(Compiled Code)) at org.apache.struts.action.ActionServlet.process(ActionServlet.java(Inl ined Compiled Code)) at org.apache.struts.action.ActionServlet.doPost( ActionServlet.java(编译代码))在 javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code)) at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code)) at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(Stric tServletInstance.java(Compiled Code)) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(Stric tLifecycleServlet.java(Compiled Code)) 在 com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecy cleServlet.java(Compiled Code)) 在 com. ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(Strict LifecycleServlet.java(Inlined Compiled Code)) at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java(Compiled Code)) at com.ibm .ws.webcontainer.servlet.ValidServletReferenceState.dispatch(V alidServletReferenceState.java(编译代码))在com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(Ser vletInstanceReference.java(内联编译代码))在com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilte rChain.java (编译代码))在 com.infostream.web.filters.HibernateSessionFilter.doFilter(HibernateS essionFilter.java(编译代码))在 com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterI nstanceWrapper.java(编译代码) ) 在 com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilte rChain.java(Compiled Code)) 在 com.infostream.web.filters.IdentificationFilter.doFilter(IdentificationFilter.java(Compiled Code)) 在 com。 ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java(编译代码))在com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilte rChain.java(编译代码))在com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDi spatch(WebAppRequestDispatcher.java(编译代码)) 在 com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebApp pRequestDispatcher.java(编译代码)) 在 com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebApp RequestDispatcher.java(编译代码) )) 在 com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java (编译代码)) 在 com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebApp Invoker.java(编译代码))在 com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java(编译代码))在 com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java(编译代码))在 com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(服务器 vletRequestProcessor。 java(编译代码))在com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSE Listener.java(编译代码))在com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnect ion.java( Compiled Code)) at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.ja va(Compiled Code)) at com.ibm.ws.http.HttpConnection.run(HttpConnection.java(Compiled Code)) at com. ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(编译代码))com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(Ser vletRequestProcessor.java(Compiled Code)) 上 com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher 上的 CacheableInvocationContext.i nvoke(CacheableInvocationContext.java(Compiled Code))。 com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnect ion.java(编译代码)) com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection. JAVA(编译代码))在 com.ibm.ws.http.HttpConnection.run(HttpConnection.java(编译代码))在 com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(编译代码) )com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(Ser vletRequestProcessor.java(Compiled Code)) 上 com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher 上的 CacheableInvocationContext.i nvoke(CacheableInvocationContext.java(Compiled Code))。 com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnect ion.java(编译代码)) com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection. JAVA(编译代码))在 com.ibm.ws.http.HttpConnection.run(HttpConnection.java(编译代码))在 com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(编译代码) )dispatchByURI(Ser vletRequestProcessor.java(Compiled Code)) at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSE Listener.java(Compiled Code)) at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest( HttpConnection.java(编译代码))在 com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.ja va(编译代码))在 com.ibm.ws.http.HttpConnection.run(HttpConnection.java(编译代码) ) ) 在 com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))dispatchByURI(Ser vletRequestProcessor.java(Compiled Code)) at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSE Listener.java(Compiled Code)) at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest( HttpConnection.java(编译代码))在 com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.ja va(编译代码))在 com.ibm.ws.http.HttpConnection.run(HttpConnection.java(编译代码) ) ) 在 com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))http.HttpConnection.readAndHandleRequest(HttpConnection.ja va(Compiled Code)) at com.ibm.ws.http.HttpConnection.run(HttpConnection.java(Compiled Code) ) at com.ibm.ws.util.ThreadPool$Worker.run (ThreadPool.java(编译代码))http.HttpConnection.readAndHandleRequest(HttpConnection.ja va(Compiled Code)) at com.ibm.ws.http.HttpConnection.run(HttpConnection.java(Compiled Code) ) at com.ibm.ws.util.ThreadPool$Worker.run (ThreadPool.java(编译代码))
我用来测试登录的代码是:
#!/usr/bin/perl -w
use WWW::Scripter;
my $urlLogin = "XXX";
my $viper = WWW::Scripter->new();
$viper->use_plugin('JavaScript');
$viper->get($urlLogin);
$viper->form_name('loginForm');
$viper->field(username => "xxx");
$viper->field(password => "xxx");
$viper->click();
如前所述,如果我使用 WWW::Mechanize 而不是 WWW::Scripter,这可以正常工作。
谁能建议我可以做些什么来删除正在发布的数据包的 Content-Type 中的字符集字段。