Friday, 1 August 2014

how to post method request in android example


public void postRequest() {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("Your URL Type");
    try
{       
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("id", "123"));
        nameValuePairs.add(new BasicNameValuePair("name", "Hiiii"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        Log.i("Response---",response );
    } catch (ClientProtocolException e)
 {
        // TODO Auto-generated catch block
    }
catch (IOException e)
{
        // TODO Auto-generated catch block
    }
}

No comments:

Post a Comment