Archivi tag: data

Android Send Post Data

Com’è possibile inviare dei dati in post ad una pagina web su piattaforma Android?
Ecco lo snippet! 🙂


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 nameValuePairs = new ArrayList(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

}

}