This question is a duplicate for sure but I need an answer and can't find it.
I need to send a Json json object to the server and retrieve another json. What I've tried so far isn't working, nothing happens.
What am I doing wrong?
The json object to send is userCreate
and the address is path
, tell me if you really need the adress and json format.
Solved, FINAL CODE:
Thread x = new Thread(){
public void run(){
Looper.prepare();
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(path);
String result = "";
try {
post.setEntity(new StringEntity(userCreate.toString()));
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
result = EntityUtils.toString(entity);
Toast.makeText(ctx,"Result: " + result + " response: " + response.getStatusLine().getStatusCode(), 10000).show();
} catch(Exception e) {
e.printStackTrace();
}
Looper.loop();
}
};
x.start();