I have the following code for a http request using DefaultHttpClient in Android, i notice the difference between handling POST and GET request. For instance, with the POST request, at first the URL is passed directly to HttpPost and then encoding is done.However, with the GET request, encoding is done first and then the url with parameters are passed. is this some kind of rule that must be followed, or can i do similar sequence of encoding and url passing for both POST and GET? thanks in advance.
// check for request method
if(method == "POST"){
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
//encode the post data
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}else if(method == "GET"){
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}