0

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();
        } 
kzs
  • 1,111
  • 5
  • 20
  • 35

1 Answers1

0

nope Sir that cant be done , follow the same way you have been doing it , i have followed a few tutorials , all of them follow the standard , and the click this link will help you What is the difference between a HTTP-Get and HTTP-POST and why is HTTP-POST weaker in terms of security Check out Mike Weller answer

Community
  • 1
  • 1
coderVishal
  • 8,369
  • 3
  • 35
  • 56