The system sends the message to the target server via URL, and obtains the return data: (Implementation Class)
1 ImportJava.io.BufferedOutputStream;2 ImportJava.io.BufferedReader;3 ImportJava.io.InputStream;4 ImportJava.io.InputStreamReader;5 ImportJava.io.OutputStream;6 ImportJava.io.OutputStreamWriter;7 ImportJava.net.URL;8 Importjava.net.URLConnection;9 Ten Public classBlazesao { One A Public Static voidCallblaze (string URL, string data)throwsexception{ -URL U =Newurl (url); -SYSTEM.OUT.PRINTLN ("Establish link ....")); the //Get Connection Object -URLConnection UC =u.openconnection (); -Uc.setdooutput (true); - //get output Stream object +OutputStream raw =Uc.getoutputstream (); -OutputStream buffered =NewBufferedoutputstream (raw); +OutputStreamWriter out =NewOutputStreamWriter (Buffered, "UTF-8"); A atSYSTEM.OUT.PRINTLN ("Send message:" +data); - out.write (data); - - Out.flush (); -SYSTEM.OUT.PRINTLN ("Close Connection"); - out.close (); in //gets the input stream to the returned data -InputStream is =Uc.getinputstream (); toBufferedReader br =NewBufferedReader (NewInputStreamReader (IS, "UTF-8")); +String line = ""; -StringBuffer Blzrspxml =NewStringBuffer (); theSystem.out.println ("Get Return Data:"); * while(line = Br.readline ())! =NULL){ $ //read return data, branch readPanax Notoginseng System.out.println (Line.trim ()); - Blzrspxml.append (Line.trim ()); the } + } A the Public Static voidMain (String args[]) { + - //Destination server address $String URL1 = "Http://10.14.30.242:9080/RES/Rule"; $ //Sent Messages -String data1 = "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?><cardrequest><seq_time_stamp> 2014325170152799504</seq_time_stamp><type>1</type><v_101>-999998</v_101><v_ 102>0.002740</v_102><v_109>111.11</v_109></cardrequest> "; - Try { the Blazesao.callblaze (url1,data1); -}Catch(Exception e) {Wuyi e.printstacktrace (); the } - } Wu -}
Output log:
Establish links .... delivered : <?xml version= "1.0" encoding= "UTF-8"?><cardrequest><seq_time_stamp> 2014325170152799504</seq_time_stamp><type>1</type><v_101>-999998</v_101><v_ 102>0.002740</v_102><v_109>111.11</v_109><v_110>111.11</v_110</cardrequest > close connection Get return data :<responsedata><r_001>s5=-9999.0</r_001><r_002>t</r_002> <r_003>y</r_003><r_004></r_004><r_005></r_005><r_006>s5_b017_others </R_006></ResponseData>
Java URL Implementation calls other systems to send messages and retrieve return data