Java uses httpconnect to send information to the server and receive feedback information

Source: Internet
Author: User

Package com.cn;
Import java. Io. bufferedreader;
Import java. Io. inputstream;
Import java. Io. inputstreamreader;
Import java. Io. objectoutputstream;
Import java.net. httpurlconnection;
Import java.net. url;
Import org. jsoup. jsoup;
Import org. jsoup. nodes. Document;
Import org. jsoup. Select. elements;
Public class HTTP {

/**
* @ Param ARGs
*/
Public static string url = "http: // 192.168.0.172/HS/androids/report. php? UN = 1 ";
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
String URLs = "http: // 127.0.0.1/HS/androids/report. php? UN = I have been here for weeds ";
Try {
URL url = new URL (URLs );
Httpurlconnection HTTP = (httpurlconnection) URL. openconnection ();
HTTP. setdoinput (true );
HTTP. setdooutput (true );
HTTP. setusecaches (false );
HTTP. setrequestmethod ("get ");
HTTP. Connect ();

Objectoutputstream OSI = new objectoutputstream (HTTP. getoutputstream ());
String curlpost = "Un = 1 ";
OSI. Write (curlpost. getbytes ("UTF-8 "));
OSI. Flush ();
OSI. Close ();
String result = "";
Inputstream merge M = http. getinputstream ();
Bufferedreader in = new bufferedreader (New inputstreamreader (Bytes m ));
String inputline;
While (inputline = in. Readline ())! = NULL ){
Result = result. Concat (inputline );
}

System. Out. println (result );
Change (result );
In. Close ();

HTTP. Disconnect ();
} Catch (exception e ){

System. Out. println ("Err ");
}

}
Public static void change (string Str)
{
Document Dc = jsoup. parse (STR );
Elements em = Dc. Select ("body ");
Em = em. Select ("Div ");
System.out.println(em.html ());

}

}

 

 

 

 

Returned results

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.