Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Login to Java site with WWW::Scripter charset issue

by mikedeklerk (Initiate)
on Oct 03, 2012 at 01:44 UTC ( #996955=perlquestion: print w/replies, xml ) Need Help??
mikedeklerk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to login to a java website using WWW::Scripter module. Using the WWW::Mechanize module works fine, but once authenticated the site has JavaScript functions that I need to call - hence needing Scripter.
After doing a large amount of troubleshooting I have found that the difference in packets sent from the click() event are the Content-Type varaibale.
Mechanize has: Content-Type: application/x-www-form-urlencoded\r\n
but Scripter has: Content-Type: application/x-www-form-urlencoded; charset="ISO-8859-1"\r\n
(This is viewed using WireShark)
This explains the error I am receiving from the website which is:

> error message: "ISO-8859-1" error stack trace: > java.nio.charset.IllegalCharsetNameException: "ISO-8859-1" > at java.nio.charset.Charset.checkName( > at java.nio.charset.Charset.lookup( > at java.nio.charset.Charset.forName( Com +piled Code)) > > at java.lang.StringCoding$DecoderCache.makeDecoder(StringCod > piled Code)) > at java.lang.StringCoding$ C +ode)) > at Metho +d) > at > piled Code)) > at java.lang.StringCoding$DecoderCache.getDecoder(StringCodi > iled Code)) > at java.lang.StringCoding.getDecoder( +ed Compiled Code)) > at java.lang.StringCoding.decode( +Code)) > at java.lang.String.<init>( Code)) > at java.lang.String.<init>( Compiled Code +)) > at +a(RequestUti > Code)) > at +ters(SRTServ > Code)) > at +rNames(SRTSe > Code)) > at javax.servlet.ServletRequestWrapper.getParameterNames(Ser +vletRequestW > Code)) > at org.apache.struts.util.RequestUtils.populate(RequestUtils > ed Code)) > at org.apache.struts.action.RequestProcessor.processPopulate +(RequestProc > Code)) > at org.apache.struts.action.RequestProcessor.process(Request +Processor.ja > va(Compiled Code)) > at org.apache.struts.action.ActionServlet.process(ActionServ > ined Compiled Code)) > at org.apache.struts.action.ActionServlet.doPost(ActionServl > iled Code)) > at javax.servlet.http.HttpServlet.service( +ompiled Code > )) > at javax.servlet.http.HttpServlet.service( +ompiled Code > )) > at +ervice(Stric > Code)) > at +ervice(Stric > Code)) > at +StrictLifecy > Code)) > at +rvice(Strict > Compiled Code)) > at +ervletInstan > Code)) > at +e.dispatch(V > Code)) > at +dispatch(Ser > Compiled Code)) > at +(WebAppFilte > Code)) > at com.infostream.web.filters.HibernateSessionFilter.doFilte +r(HibernateS > Code)) > at +lter(FilterI > Code)) > at +(WebAppFilte > Code)) > at com.infostream.web.filters.IdentificationFilter.doFilter( +Identificati > Code)) > at +lter(FilterI > Code)) > at +(WebAppFilte > Code)) > at +ndleWebAppDi > spatch( Code)) > at +spatch(WebAp > Code)) > at +rward(WebApp > Code)) > at +pInvoker.jav > a(Compiled Code)) > at +nHook(WebApp > Code)) > at +.handleInvoc > ation( Code)) > at +ionContext.i > nvoke( Code)) > at +tchByURI(Ser > Code)) > at +.service(OSE > Code)) > at +(HttpConnect > Code)) > at +onnection.ja > va(Compiled Code)) > at +mpiled Code) > ) > at$ +piled Code))
The code I'm using to test the login is:
#!/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();
As mentioned before this works fine if I use WWW::Mechanize instead of WWW::Scripter. Can anyone suggest what I can do to remove the charset field in the Content-Type of the packet being POST'ed.

Replies are listed 'Best First'.
Re: Login to Java site with WWW::Scripter charset issue
by Anonymous Monk on Oct 03, 2012 at 02:43 UTC

      Whoops, unfinished though there :)

      my($type, $charset) = $h->content_type_charset; $h->content_type( $type ); # ditch charset

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://996955]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2018-06-24 06:03 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.