Pavithra Mohan
Pavithra Mohan

Reputation: 87

How do I receive value in website from android phone

I am sending the value from android phone to a website. The website is registered online through some free sources.

The code is,

public class HttpStorage extends AsyncTask{
   protected void onPreExecute() {
        super.onPreExecute();
   }
   protected void onPostExecute(Integer result) {
   }

public void postData() {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new      
    HttpPost("http://pavithrakrishnakumar.simplesite.com/");

    try {
        List <NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("IDToken1", "username"));
        nameValuePairs.add(new BasicNameValuePair("IDToken2", "password"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }
}

@Override
protected Object doInBackground(Object... arg0) {
        postData();
    return null;
}
}

Now I am not getting any error in android side. How do I retrieve the value in the above mentioned site

Upvotes: 1

Views: 153

Answers (2)

Pawan Yadav
Pawan Yadav

Reputation: 1782

        public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new      
    HttpPost("http://pavithrakrishnakumar.simplesite.com/");

    try {
         List <NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("IDToken1", "username"));
        nameValuePairs.add(new BasicNameValuePair("IDToken2", "password"));


        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

        if(response != null) {

          int statuscode = response.getStatusLine().getStatusCode();

           if(statuscode==HttpStatus.SC_OK) {
            String strResponse = EntityUtils.toString(response.getEntity());

          }
       }

 } catch (ClientProtocolException e) {
   // TODO Auto-generated catch block
 } catch (IOException e) {
        // TODO Auto-generated catch block
 }
 }

Upvotes: 0

Tamilselvan Kalimuthu
Tamilselvan Kalimuthu

Reputation: 1532

<?php
    $IDToken1 = $_POST['IDToken1'];
    $IDToken2 = $_POST['IDToken2'];

This is how u can retrieve the data from a post request in that script..

Upvotes: 1

Related Questions