It can be implemented using the HttpClient framework that comes with Android.
GET Method Pass Parameter
First put the parameters in the list, and then URL code the parameters
list<basicnamevaluepair> params = new linkedlist<basicnamevaluepair> ();
Params.add (New Basicnamevaluepair ("param1", "data")); Add parameter 1
Params.add (New Basicnamevaluepair ("param2", "value2"));//Add Parameter 2
String param = Urlencodedutils.format (params, "UTF-8");//Parameter encoding
String BASEURL = "Server interface full URL";
HttpGet GetMethod = new HttpGet (BaseUrl + "?" + param);//url and parameter stitching
HttpClient HttpClient = new Defaulthttpclient ();
try {
HttpResponse response = Httpclient.execute (GetMethod); Initiating a GET request
LOG.I (TAG, "Rescode =" + Response.getstatusline (). Getstatuscode ()); Get the response code
LOG.I (TAG, "result =" + entityutils.tostring (response.getentity (), "Utf-8"));//Get Server response content
} catch (Clientprotocolexception e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
2. Post Mode pass parameters
As with the Get method, first put the parameter in the list
params = new linkedlist<basicnamevaluepair> ();
Params.add (New Basicnamevaluepair ("param1", "POST Method"));//Add parameter 1
Params.add (New Basicnamevaluepair ("Param2", "second parameter"));//Add Parameter 2
try {
HttpPost Postmethod = new HttpPost (BASEURL);//Create a POST request
Postmethod.setentity (New urlencodedformentity (params, "utf-8")); Fill in the post entity with the parameters
HttpResponse response = Httpclient.execute (Postmethod); Execute POST method
LOG.I (TAG, "Rescode =" + Response.getstatusline (). Getstatuscode ()); Get the response code
LOG.I (TAG, "result =" + entityutils.tostring (response.getentity (), "Utf-8")); Get response Content
} catch (Unsupportedencodingexception e) {
E.printstacktrace ();
} catch (Clientprotocolexception e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
How Android get/post implement multi-parameter requests