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 41 42 43 44 45
| class GetServerDataTask extends AsyncTask<String,String,JSONArray> {
private ProgressDialog pDialog;
/** Appelée dans le thread principal (on a donc le droit de toucher à l'UI) avant le démarrage */
public void onPreExecute() {
}
/** Appelée dans un thread à part, recoit les mêmes paramètres que ceux passés à "execute()"
* @return */
public JSONArray doInBackground(String ... urls)
{
// Envoie de la commande http
try{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("Nom", Nom.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("Prenom", Prenom.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("Ville", Ville.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("Code postal", Code_postal.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("Adresse", Adresse.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("Email", Email.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("Pass", Pass.getText().toString()));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL2);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
//String entityStr = EntityUtils.toString(entity);
//return new JSONArray(entityStr);
}catch(Exception e){
Log.e("GetServerDataTask", "Erreur de récupération des données",e);
}
return null;
}
/**
* Appelé dans le thread UI, avec le retour de doInBackground. On peut donc modifier l'UI ici.
*/
public void onPostExecute(JSONArray result) { |
Partager