我正面临发送 jsonstring 的问题,但该字符串为空。
当我使用这个 php 代码来查看我是否正在接收一个字符串以及我得到什么时:
POST:
Array
(
)
GET:
Array
(
[data] =>
)
这是我的安卓代码:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.myserver.nl/locatie.php?data=");
httppost.setHeader("Content-type", "application/json");
// Create json object here...
json = new JSONObject();
try {
json.put("id", "0612838");
json.put("longitude", "-143.406417");
json.put("latitude", "32.785834");
json.put("timestamp", "10-10 07:56");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/// create StringEntity with current json obejct
try {
se = new StringEntity(json.toString());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httppost.setEntity(se);
try {
response = httpclient.execute(httppost);
String temp = EntityUtils.toString(response.getEntity());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
有人看到我做错了吗?