I've dealt with a lot of script languages like PHP and JavaScript. I have little experience with Java and Android.
I want to send POST data through PHP script and show it on the screen, what should I do?
php httpconnection java client-server android
Using the Http Client in the Apache Commons library is easy. It's already included in Android. If you follow the example below, you can do HTTP Post simply.
public void postData() {
// // Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
httpPost httppost = new HttpPost ("http://www.site address.com/script.php"));
try {
// Use the appropriate data format as shown below
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "Hi"));
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
}
}
© 2024 OneMinuteCode. All rights reserved.