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 );