Java HTTP Request

Source: Internet
Author: User
Package COM. quugames. fish. util; import Java. io. bufferedreader; import Java. io. inputstreamreader; import java.net. URL; import java.net. urlconnection; import net. SF. JSON. jsonobject; /*** purchase verification ** @ author administrator */public class buyvalidation {/*** send a get Method Request to a specified URL * @ Param URL send the request URL * @ return URL remote resource response */public static void sendget (string URL) {string result = ""; bufferedreader in = NULL; try {URL Realurl = new URL (URL); urlconnection conn = realurl. openconnection (); Conn. connect (); In = new bufferedreader (New inputstreamreader (Conn. getinputstream (); string line; while (line = in. readline ())! = NULL) {result + = line;} If (result! = NULL & result. length ()> 1) {// system. out. println (result); jsonobject JB = jsonobject. fromobject (result); system. out. println ("the returned state is:" + JB. getstring ("state"); system. out. println ("Returned Code:" + JB. getstring ("Code") ;}} catch (exception e) {system. out. println ("an exception occurred when sending a GET request! "+ E); E. printstacktrace () ;}} public static void main (string [] ARGs) {string url = "http: // localhost: 8080/webserver/server. JSP "; sendget (URL );}}

Server:

Jsonobject JSON = new jsonobject (); JSON. element ("State", "0"); JSON. element ("code", "## WEF #"); // sends an out message to the client. println (JSON );

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.