Java background implementations use URLs to call someone else's interface and get the value returned by the interface
Parameter jsonstr is content, path interface URL address public string sendpost (string jsonstr, String path) throws IOException {byte[] data = jsons
Tr.getbytes ();
Java.net.URL URL = new Java.net.URL (path);
Java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openconnection ();
Conn.setrequestmethod ("POST"); Conn.setconnecttimeout (5 * 1000);/Set connection timeout of 5 seconds conn.setreadtimeout (20 * 1000);/set read timeout of 20 seconds//Use URL connection for output, will DoO
The UTPUT flag is set to True Conn.setdooutput (true);
Conn.setrequestproperty ("Content-type", "text/xml;charset=utf-8");
Conn.setrequestproperty ("content-encoding", "gzip");
Conn.setrequestproperty ("Content-length", String.valueof (Data.length));
OutputStream OutStream = Conn.getoutputstream ();//returns the output stream Outstream.write (data) written to this connection; Outstream.close ()//close stream String msg = ""//Save response information after calling HTTP service//If the request response code is 200, the success if (conn.getresponsecode () = 200) {//HTTP server-side return encoding is UTF-8, it must be set to UTF-8, keep coding unified, otherwise will appear Chinese garbled bufferedreader in = new BufferedReader (New InputstreamreAder (Conn.getinputstream (), "UTF-8"));
msg = In.readline ();
In.close ();
Conn.disconnect ();//Disconnect return msg; }