Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak wysłać i odebrać dane przez POST?
Saki
post 20.10.2012, 11:57:49
Post #1





Grupa: Zarejestrowani
Postów: 240
Pomógł: 2
Dołączył: 5.12.2010
Skąd: Fulda

Ostrzeżenie: (0%)
-----


Witam, mam mały problem, chce z Androida App inputa wysłać dane i odebrać wiadomość którą serwer odpowiedział, np. OK.

  1. package eu.itunix.test;
  2.  
  3. import android.os.Bundle;
  4.  
  5. public class MainActivity extends Activity {
  6.  
  7. public void postData(String toPost) {
  8. // Create a new HttpClient and Post Header
  9. HttpClient httpclient = new DefaultHttpClient();
  10. HttpPost httppost = new HttpPost("http://api.pytanu.pl/testr.php");
  11.  
  12. //This is the data to send
  13. String MyName = 'adil'; //any data to send TUTAJ BŁĄD?! XXX # Jeżeli zrobię >"< to psuje cały skrypt a jeżeli zrobię >'< to pokazuje że jest błąd tylko w tej linii XXX
  14.  
  15. try {
  16. // Add your data
  17. List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
  18. nameValuePairs.add(new BasicNameValuePair("action", MyName));
  19.  
  20. httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  21.  
  22. // Execute HTTP Post Request
  23.  
  24. ResponseHandler<String> responseHandler = new BasicResponseHandler();
  25. String response = httpclient.execute(httppost, responseHandler);
  26.  
  27. //This is the response from a php application
  28. String reverseString = response;
  29. Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();
  30.  
  31. } catch (ClientProtocolException e) {
  32. Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
  33. // TODO Auto-generated catch block
  34. } catch (IOException e) {
  35. Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
  36. // TODO Auto-generated catch block
  37. }
  38.  
  39. }//end postData()
  40.  
  41. }


--------------------
Moje serwisy: services.itunix.eu | spytajsie.com

Server: Debian; Desktop: Mac Mini 10.8.1, ArchLinux XFCE
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 25.07.2025 - 07:54