I want to know the POST method instead of the GET method.
Sent value to how how to write.
I can not find in the GET example send the value to be placed where
Friends can demonstrate to me to see it?
I write POST method
POST method example:
private POST()
{
HttpPost httpRequest2 = new HttpPost("ip");
List<NameValuePair> params2 = new ArrayList<NameValuePair>();
params2.add(new BasicNameValuePair("Q1","b"));
//Ready to send the value of the
try
{
httpRequest2.setEntity(new UrlEncodedFormEntity(params2, HTTP.UTF_8));
httpResponse2 = new DefaultHttpClient()
.execute(httpRequest2);
if (httpResponse2.getStatusLine().getStatusCode() == 200)
{
String strResult2 = EntityUtils.toString(httpResponse2.getEntity());
return strResult2;
}
} catch (Exception e)
{
e.printStackTrace();
}
return null;
}
GET method of teaching which is found on the network.
GET method example:
public StringGet() throws Exception {
String strResult = "";
String httpUrl = "ip";
HttpGet httpRequest = new HttpGet(httpUrl);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(httpRequest);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
strResult = EntityUtils.toString(httpResponse.getEntity());
tv.setText(strResult);
} else {
tv.setText("fail");
}
return strResult;
}
}
Here is a sample code to send data by HttpGet method,