Witam, mam mały problem, chce z Androida App inputa wysłać dane i odebrać wiadomość którą serwer odpowiedział, np. OK.
package eu.itunix.test;
import android.os.Bundle;
public class MainActivity extends Activity {
public void postData
(String toPost
) { // Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://api.pytanu.pl/testr.php");
//This is the data to send
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
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("action", MyName));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response
= httpclient.
execute(httppost, responseHandler
);
//This is the response from a php application
String reverseString
= response
; Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
// TODO Auto-generated catch block
Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
// TODO Auto-generated catch block
}
}//end postData()
}