Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Requête POST en Json

Featured Replies

Posté(e)

Bonjour :),

Je réalise une application Android qui doit communiquer vers un serveur Tornado (Python).

Pour faire simple, je récupere la chaine de caractère "surnom" d'un EditText et l'envoie vers le serveur grâce à la méthode httpPost. Je vois que mon serveur Tornado récupère la requête POST mais pas la chaine de caractère que j'envoie. Je pense qu'il veut du JSON. Savez-vous comment je peux simplement envoyer la valeur en tant que object JSON?

Voici mon code:

//------------------------SERVEUR----------------------------

			        StringBuffer stringBuffer = new StringBuffer("");
			        BufferedReader bufferedReader = null;

					try {
			        	HttpClient httpClient = new DefaultHttpClient();
			        	HttpPost httpPost = new HttpPost("http://192.168.0.1:8888");
			        	List<NameValuePair> parametres = new ArrayList<NameValuePair>();
			        	parametres.add(new BasicNameValuePair("surnom",((TextView) findViewById(R.id.surnom)).getText().toString()));

			        	UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parametres);
			        	httpPost.setEntity(formEntity);

			        	HttpResponse httpResponse = httpClient.execute(httpPost);
			        			bufferedReader = new BufferedReader(
			        					new InputStreamReader(httpResponse.getEntity().getContent()));

			        			String ligneLue = bufferedReader.readLine();
			        			while (ligneLue!=null){
			        				stringBuffer.append(ligneLue);
			        				ligneLue = bufferedReader.readLine();        				

			        			}


			        } catch (Exception e){

			        	Log.e("Exception1", e.getMessage());

			        } finally {
			        	if (bufferedReader !=null){
			        		try{
			        			bufferedReader.close();
			        		} catch (IOException e){
			        			Log.e("Exception2", e.getMessage());
			        		}
			        	}
			        }

			        Log.i("Exception3", stringBuffer.toString());


				}
				});

Merci d'avance,

Florent

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.