0

I have the following code:

JSONObject jsonRequest = new JSONObject();
jsonRequest.put("id", 1);
jsonRequest.put("method", "mymethod");
entity = new JSONEntity(jsonRequest);
HttpPost request = new HttpPost("http://192.168.1.103/foo/bar.php");
request.setEntity(entity);
HttpResponse response = httpClient.execute(request);

Irrelevant code removed

It posts to a .php page. On the .php page I call var_dump to check the content of both $_POST and $_GET. Both are empty.

Any idea?

Pim Reijersen
  • 1,123
  • 9
  • 33
  • localhost point to android emulator/device not to the host of emulator use my_computer_name or ip address instead – Selvin Apr 20 '11 at 13:14
  • correct, but thats not the problem. I have that setup correctly in the actual code. I edited my question. – Pim Reijersen Apr 20 '11 at 13:15
  • try HttpGet("http://192.168.1.103/foo/bar.php?id=1&method=mymethod") i think $_POST/$_GET is for form or query string not for json – Selvin Apr 20 '11 at 13:21
  • Yes, that will work. Its not the awnser I'm looking for because I'm pretty sure that there must be a way to post the JSONEntity. But atleast I can continue development using your approach. – Pim Reijersen Apr 20 '11 at 13:24
  • i don't know PHP but what u need is reading the "file" ({"id":1, "method":"mymethod"}) whith was sensed from android and parse it in some kinde of json API in PHP – Selvin Apr 20 '11 at 13:28
  • The PHP server does not receive anything. – Pim Reijersen Apr 20 '11 at 13:29

1 Answers1

0

Solved it. Obtain the data in php:

$input = file_get_contents('php://input');
Pim Reijersen
  • 1,123
  • 9
  • 33