1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
Log.i("POST", "Creation params");
HttpPost httppost = new HttpPost("http://www.url.fr/script.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("nom",nom.getText().toString()));
//....
nameValuePairs.add(new BasicNameValuePair("invitation","1"));
Log.i("POST", "Codage params");
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
Log.e("POST", "Encodage");
}
Log.i("POST", "Envoie requete");
HttpClient httpclient = new DefaultHttpClient();
try {
//résultats ne changent pas avec ou sans le header
httppost.setHeader("Content-type","application/x-www-form-urlencoded");
HttpResponse response=httpclient.execute(httppost);
Log.i("POST",convertStreamToString(response.getEntity().getContent()));
} catch (ClientProtocolException e) {
Log.e("POST", "CPE lors de l'envoi");
e.printStackTrace();
} catch (IOException e) {
Log.e("POST", "IOE lors de l'envoi");
}
}
}; |
Partager