Can someone provide an example of android code to send simple data to PHP server? I need to just send several string, double, and int variables from a form that was created on android device, convert those entries into a pdf document, then send that back to android. If I could just get a sample of at least sending it to server that would help a lot. Thanks.
Asked
Active
Viewed 110 times
-4
-
2possible duplicate of [How to do a HTTP Post in Android?](http://stackoverflow.com/questions/4470936/how-to-do-a-http-post-in-android) – mbeckish Jun 06 '12 at 19:52
1 Answers
1
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
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
}
}

Adeel
- 2,901
- 7
- 24
- 34

Munish Kapoor
- 3,141
- 2
- 26
- 41