Executing a HTTP POST Request with HttpClient

//  here i am explaining how to send some data to server

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.util.Log;

public class SendInfo {
    private boolean isPosted = false;

    public SendInfo() {
    }

    public boolean PostData() {
        try {
  
            HttpClient mClient = new DefaultHttpClient();
            HttpPost mpost = new HttpPost("http://www.webimm.com/");
         List<NameValuePair> nameValuepairs = new ArrayList<NameValuePair>(2);
            nameValuepairs.add(new BasicNameValuePair("101",
                    "sravankumar@vizser.com"));
            Log.w("send info1 ", "send info1");
            nameValuepairs.add(new BasicNameValuePair("102",
                    "suryaprakash@vizser.com"));
            Log.w("send info2 ", "send info2");
            mpost.setEntity(new UrlEncodedFormEntity(nameValuepairs));
            HttpResponse responce = mClient.execute(mpost);
            HttpEntity entity = responce.getEntity();
           BufferedReader buf = new BufferedReader(new InputStreamReader(
                    entity.getContent()));
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = buf.readLine()) != null) {
                Log.w(" data is ", line);
            }
            isPosted = true;
            return isPosted;
        } catch (UnsupportedEncodingException e) {
         
            Log.w(" error ", e.toString());
        } catch (Exception e) {

            Log.w(" error ", e.toString());
        }

        return isPosted;

    }

}

Search & Download lots of Eclipse-Android Tutorials:-
  Using Pdf Wallet you can find useful and free Android Tutorials.


Search 

Please Select File-Format

PDF  - eBooks in pdf format.
PPT  - Presentations:2003.
PPTX- Presentations:2007+.
DOC - Microsoft Word Files:2003.
DOCXMicrosoft Word Files:2007+.
XLS  - Excel File format:2003.
XLSX - Excel File Format:2007+.
CHM - Compiled Help Files.
RTF  - Rich Text format.
TXT  - Text Files. 

1 comment:

  1. Download Best Android App Store for downloading Android apps and games 9Apps APK

    ReplyDelete