Mechanize Timeout

116 views
Skip to first unread message

Jose Espinoza

unread,
Nov 26, 2014, 2:52:04 PM11/26/14
to mecha...@googlegroups.com
Hello.

i have a code like this

        MechanizeAgent agent = new MechanizeAgent();  

        Document page=agent.get(url);

        Forms forms=page.forms();

        Form form=forms.get(0);

        form.get("q").set(query);

        Resource response=form.submit();

and my question is, i need to set a connection timeout because sometimes mechanize just stuck ...

Thanks very much!

John Heintz

unread,
Nov 26, 2014, 3:32:01 PM11/26/14
to Jose Espinoza, mecha...@googlegroups.com
Hi Jose,

Of course I'm interested in how mechanize might get stuck... but the answer to your question is to set the timeout on the instance of HttpClient in use.

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpParams params = httpClient.getParams();
params.setConnectionTimeout(httpParams, connectionTimeoutMillis);
params.setSoTimeout(httpParams, socketTimeoutMillis);
MechanizeAgent agent = new MechanizeAgent(httpClient);   

That constructor argument allows you to control the underlying http communication as needed.

Cheers
John


--
You received this message because you are subscribed to the Google Groups "mechanize4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanize4j...@googlegroups.com.
Visit this group at http://groups.google.com/group/mechanize4j.
For more options, visit https://groups.google.com/d/optout.



--
John D. Heintz
Agile, Lean, and everything in between

President, Gist Labs
Senior Consultant, Cutter Consortium

Twitter: @jheintz Phone: 512-633-1198


Jose Espinoza

unread,
Nov 26, 2014, 5:51:15 PM11/26/14
to mecha...@googlegroups.com, jose...@gmail.com
Thank you so much John.

Your answer was very helpful.
For example if it get ban from a website the get method just stuck waiting for response for ever, i dont know why but it happens...
Reply all
Reply to author
Forward
0 new messages