Package COM. potevio. mobilenet; </P> <p> Import Java. io. bufferedreader; <br/> Import Java. io. ioexception; <br/> Import Java. io. inputstream; <br/> Import Java. io. inputstreamreader; <br/> Import Java. io. outputstreamwriter; <br/> Import java.net. URL; <br/> Import java.net. urlconnection; </P> <p> public class testpost {</P> <p> Public static void testpost () throws ioexception {</P> <p> // connection address <br/> string Surl =" Http: // 219.238.180. ***: 80/.../loginservlet? Command = login "; </P> <p>/** <br/> * You must first talk to urlconnection under the URL. Urlconnection can be easily obtained from the URL. For example: // using <br/> * java.net. URL and // java.net. urlconnection <br/> */<br/> URL url = new URL (Surl); <br/> urlconnection connection = URL. openconnection (); </P> <p>/** <br/> * then set the connection to the output mode. Urlconnection is usually used as input, such as downloading a Web page. <Br/> * by setting urlconnection as output, you can transmit data to your web page. The following describes how to: <br/> */<br/> connection. setdooutput (true); <br/>/** <br/> * Finally, to get outputstream, constrain it to writer and put it into post information for simplicity, example :... <br/> */<br/> outputstreamwriter out = new outputstreamwriter (connection <br/>. getoutputstream (), "UTF-8"); <br/> out. write ("user_account = Admin & user_password = ******"); // The Key to post! <Br/> // remember to clean up <br/> out. flush (); <br/> out. close (); <br/>/** <br/> * to send a post that looks like this: <br/> * post/Jobsearch. cgi HTTP 1.0 accept: <br/> * text/plain Content-Type: Application/X-WWW-form-urlencoded <br/> * Content-Length: 99 username = Bob Password = someword <br/> */<br/> // once the message is sent successfully, you can obtain the server response using the following method: <br/> string scurrentline; <br/> string stotalstring; <br/> scurrentl INE = ""; <br/> stotalstring = ""; <br/> inputstream l_urlstream; <br/> l_urlstream = connection. getinputstream (); <br/> // The legendary Three-tier package! <Br/> bufferedreader l_reader = new bufferedreader (New inputstreamreader (<br/> l_urlstream); <br/> while (scurrentline = l_reader.readline ())! = NULL) {<br/> stotalstring + = scurrentline + "/R/N"; </P> <p >}< br/> system. out. println (stotalstring); <br/>}</P> <p> Public static void main (string [] ARGs) throws ioexception {</P> <p> testpost (); </P> <p >}</P> <p>
The above code passes the test to obtain the Static Page code after logon.
If you are interested, test the address by yourself. Note that the address is submitted and the parameters must be consistent.