Two ways to send post and get requests in Java
1.URL
2.httpclient
The first way:
Send request in URL form
The second way:
commons-httpclient-3.1.jar;
Import Org.apache.commons.httpclient.httpclient;import Org.apache.commons.httpclient.methods.postmethod;import Org.apache.commons.httpclient.params.httpmethodparams;public class Test {public static void main (string[] args) { String info = null; try {HttpClient HttpClient = new HttpClient (); Postmethod post = new Postmethod ("http://192.168.11.11/sssssssss/ssAction!updateYunMasCallBack.action");//POS T.getparams (). Setparameter (Httpmethodparams.http_content_charset, "GBK"); Post.addparameter ("Spcode", "sssssss"); Post.addparameter ("LoginName", "ssss"); Post.addparameter ("Password", "ssssss"); Post.addparameter ("Messagecontent", "You have an item numbered 23 you need to handle 56 of the transaction. "); Post.addparameter ("Usernumber", "15680805571"); Post.addparameter ("SerialNumber", "12345678901234567890"); Post.addparameter ("Scheduletime", "" "); Post.addparameter ("Extendaccessnum", "" "); PoSt.addparameter ("F", "1"); Httpclient.executemethod (POST); info = new String (Post.getresponsebody (), "GBK"); SYSTEM.OUT.PRINTLN (info); } catch (Exception e) {e.printstacktrace (); } }}
Http (Java) post and get methods