似乎Android應用程序發送JSON對象沒有問題,但是當我收到我得到一個:無法從應用程序接收JSON數據
「通知:未定義指數」
發送的對象的代碼是在這裏:
public void sendJson(String name1, String name2) throws JSONException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://example.com/JSON_FOLDER/JSON2/parseData.php");
HttpResponse response;
JSONObject json = new JSONObject();
try {
json.put("name1", name1);
json.put("name2", name2);
StringEntity se = new StringEntity(json.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httppost.getParams().setParameter("json", json); // new code
//Execute HTTP POST request
httppost.setEntity(se);
response = httpclient.execute(httppost);
if(response != null) {
str = inputStreamToString(response.getEntity().getContent()).toString();
Log.i("DATA", "Data send== " + str);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
在服務器端:
$json = $_POST['name1'];
$decoded = json_decode($json, TRUE);
和我得到了不確定的指標通知書。
我建議你看一看原始的結果說,無論是在服務器或客戶端。 – arkascha
這樣的:*** file_get_contents('php:// input'); ***我試過但沒有結果 – t0s
在服務器端你把應答轉儲到日誌文件中(例如php syslog())。在客戶端:取決於你的平臺,我不知道android。最簡單的可能是使用像Wireshark這樣的網絡嗅探器。 – arkascha