Java simulated page Logon

Source: Internet
Author: User

 Public static void main (string [] ARGs) {<br/> httpclient client = new httpclient (); <br/> namevaluepair [] namevaluepairs ={< br/> New namevaluepair ("username", "AAA"), <br/> New namevaluepair ("passwd ", "123456") <br/>}; <br/> postmethod = new postmethod ("Logon URL"); <br/> postmethod. setrequestbody (namevaluepairs); <br/> int stats = 0; <br/> try {<br/> stats = client.exe cutemethod (postmethod); <br />} Catch (httpexception e) {<br/> E. printstacktrace (); <br/>}catch (ioexception e) {<br/> E. printstacktrace (); <br/>}< br/> postmethod. releaseconnection (); // it is best to release the previous resources <br/> cookiespec = cookiepolicy. getdefaspec SPEC (); <br/> cookie [] cookies = cookiespec. match ("Domain Name", 80/* port */, "/", false, client. getstate (). getcookies (); <br/> for (COOKIE: cookies) {<br/> system. out. println (cook IE. getname () + "#" + Cookie. getvalue (); <br/>}</P> <p> httpmethod = NULL; <br/> string encode = "UTF-8"; // page encoding, by access page changes <br/> string Referer = "http: // domain name"; // http://www.163.com <br/> method = new getmethod ("url2 "); // subsequent operations <br/> method. getparams (). setparameter ("HTTP. useragent "," Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) "); <br/> method. setRequestHeader ("Referer", Referer); </P> <p> client. getparams (). Setcontentcharset (encode); <br/> client. getparams (). setsotimeout (300000); <br/> client. getparams (). setparameter (httpmethodparams. retry_handler, new defaulthttpmethodretryhandler (10, true); </P> <p> try {<br/> stats = client.exe cutemethod (method ); <br/>} catch (httpexception e) {<br/> E. printstacktrace (); <br/>}catch (ioexception e) {<br/> E. printstacktrace (); <br/>}< br/> If (Stats = httpstatus. SC _ OK) {<br/> system. Out. println ("submitted successfully! "); </P> <p >}< br/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.