Thursday, January 13, 2011

Executing a HTTP POST Request with HttpClient


Executing A HTTP POST Request with HttpClient.

 public void postData() { 
        // Create a new HttpClient and Post Header 
        HttpClient httpclient = new DefaultHttpClient(); 
        HttpPost httppost = new HttpPost(""); 
        try { 
            // Add your data 
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
            nameValuePairs.add(new BasicNameValuePair("id", "2")); 
           nameValuePairs.add(new BasicNameValuePair("stringdata", "Vijayakumar!")); 
           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
           // Execute HTTP Post Request 
           HttpResponse response = httpclient.execute(httppost); 
       } catch (ClientProtocolException e) { 
           // TODO Auto-generated catch block 
       } catch (IOException e) { 
           // TODO Auto-generated catch block 

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...