Joke Collection Website - Public benefit messages - How does JAVA call the interface?
How does JAVA call the interface?
String send post(String jsonStr,String path)\ x0d \ throws io exception { \ x0d \ byte【】data = jsonStr . getbytes(); \ x0d \ java.net.url URL = newjava.net.url (path); \ x0d \ Java . net . httpur connection conn = \ x0d \(Java . net . httpur connection)URL . open connection(); \ x0d \ conn . setrequestmethod(“POST“); \ x0d \ conn . setconnecttimeout(5 * 1000); //Set the connection timeout to 5 seconds \ x0d \ conn.set readtimeout (20 *1000); //Set the read timeout to 20 seconds \x0d\ // Use URL connection for output, and then set the DoOutput flag to true \ x0d \ conn.set dooutput (true); \ x0d \ \ x0d \ conn . setrequestproperty(“Content-Type“,“text/XML; charset = UTF-8“); \ x0d \//conn . setrequestproperty(“Content-Encoding“,“gzip“); \ x0d \ conn . setrequestproperty(“Content-Length“,string . value of(data . Length)); \ x0d \ output stream out stream = conn . get output stream(); //Returns the output stream \ x0d \ outbound.write (data) written to this connection; \ x0d \ out stream . close(); //Close stream \ x0d \ Stringmsg = ""; //Save the response information after calling the http service \x0d\ // If the request response code is 200, it means success \ x0d \ if (conn.getResponse code () = = 200) {\ x0d \//The code returned by the HTTP server is UTF-8. Therefore, it must be set to UTF-8 to keep the coding uniform, otherwise Chinese garbled code \ x0d \ buffered reader in = new buffered reader (\ x0d \ (input stream) conn.getinputstream (), "UTF-8") will appear; \ x0d \ msg = in . readline(); \ x0d \ in . close(); \ x0d \ } \ x0d \ conn . disconnect(); //Disconnect \ x0d \ return msg; \x0d\ }
- Related articles
- Is there a 3-day grace period for flower buds? How long is it overdue to call Hua Bai?
- How to pay a New Year call to the boss?
- After Ctrip booked the ticket, Ctrip now told me that the airline flight was cancelled. What should I do?
- I received a short message saying that I didn't participate in the three screening of nucleic acid.
- Special loan for epidemic situation
- Flower bud repayment successful notification SMS
- Zhengzhou issued a red rainstorm warning, and the viaduct changed into a parking lot every second. What other measures has the local government taken?
- Why did I receive your message to open 2 1M internet service, and then there was no network? . .
- How to type TIC-tac-toe when sending text messages by mobile phone?
- What is network arbitration?