I'm trying to set up a PHP API for my Android application to interact with, my problem is that the post data never seems to get posted and I can never retrieve the response body (HTML/TXT) from the URL given.
My code
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
try {
HttpClient client = new DefaultHttpClient();
HttpPost clientpost = new HttpPost("http://192.168.1.129/updateMain.php");
try {
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("_id", "1"));
params.add(new BasicNameValuePair("job_name", "Test"));
clientpost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = client.execute(clientpost);
String responseBody = EntityUtils.toString(response.getEntity());
} catch(Exception e)
{
Log.e("Error", e.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
If I can post data then I will be able to post JSON to the server and retrieve JSON from the server, thus overcoming the biggest hurdle I have at the moment.
Any help greatly appreciated.