Tuesday, 12 August 2014

how to use http post method in android


call following method

executeMultipartPost("username","password","https://your post url");

use this method

 public static void executeMultipartPost(String username, String password, String url) {

            try {

                HttpClient client = new DefaultHttpClient();
                HttpPost poster = new HttpPost(url);

                MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

                entity.addPart("username", new StringBody(username));

                entity.addPart("password", new StringBody(password));

                 poster.setEntity(entity);

                client.execute(poster, new ResponseHandler<Object>() {
                   
                public Object handleResponse(HttpResponse response)throws ClientProtocolException, IOException {

                        HttpEntity respEntity = response.getEntity();
                        String jsonData = EntityUtils.toString(respEntity);
                       
                        Log.d("Response:json", jsonData);
               
                       return null;
                    }
               
                });
            } catch (Exception e) {
                // do something with the error
                System.out.println("!!!!!!!!!!!!"+e);
            }
        }

No comments:

Post a Comment