你可以試試這段代碼,它會給你更多關於腳本中發生了什麼的信息。
然後檢查你的android代碼中的響應。
<?php
// array for JSON response
$response = array();
// Check request method -- for some reason??
if($_SERVER["REQUEST_METHOD"]=="POST"){
// check for required fields
if (isset($_POST['OrderSummary'])) {
$data = $_POST['OrderSummary'];
$json = json_decode($data,true);
$my_file = 'text.txt';
$result = file_put_contents($my_file,$json);
$response["success"] = 1;
$response["message"] = "Number of bytes written = " .$results;
}
else{
$response["success"] = 0;
$response["message"] = "Parameters not correctly formatted";
}
else{
$response["success"] = 2;
$response["message"] = "Somebody is not using the POST request method!";
}
echo json_encode($response);
?>
編輯:
我不明白爲什麼要檢查的請求方法。但是我仍然保留在PHP腳本中。
請發佈錯誤消息 – Webdesigner
您使用的是哪個版本的PHP? – Barns
@ Barns52我使用php 5.6.30 –