1
sync.php位於本地主機,通過該主機將數據發送到服務器以將文件sync1.php, 但在執行本地主機上的sync.php時,僅給出錯誤。該sync.php代碼如下:cURL在從本地主機向活動服務器發送數據時發生錯誤
include_once('db/connection.php');
$len = $_REQUEST['key']; echo '<br>';
$sqlmob = "SELECT * FROM tblqeue limit 1";
$result = mysqli_query($conn, $sqlmob);
$res = mysqli_fetch_assoc($result);
$serialNo = $res['serialNo'];
$customerName = $res['customerName'];
$phoneNo = $res['phoneNo'];
$mail = $res['mail'];
$customerPincode = $res['customerPincode'];
$customerCity = $res['customerCity'];
$customerState = $res['customerState'];
$warrantyStatus = $res['warrantyStatus'];
$productDescription = $res['productDescription'];
$serviceType = $res['serviceType'];
$typeOfRepair = $res['typeOfRepair'];
$productFamily = $res['productFamily'];
$serv_charges = $res['serv_charges'];
$problemReported = $res['problemReported'];
$techComment = $res['techComment'];
$createdUser = $res['createdUser'];
$location = $res['location'];
$reloc = $res['rloc'];
//curl starts
$data = array(array (
'length' => $len,
'serialNo' => $serialNo,
'customerName' => $customerName,
'phoneNo' => $phoneNo,
'mail' => $mail,
'customerPincode' => $customerPincode,
'customerCity' => $customerCity,
'customerState' => $customerState,
'warrantyStatus' => $warrantyStatus,
'productDescription' => $productDescription,
'serviceType' => $serviceType,
'typeOfRepair' => $typeOfRepair,
'productFamily' => $productFamily,
'serv_charges' => $serv_charges,
'problemReported' => $problemReported,
'techComment' => $techComment,
'createdUser' => $createdUser,
'location' => $location,
'rloc' => $reloc
));
//print_r($data);echo '<br>';echo '<br>';
// json encode data
$data_string = json_encode($data);
//print_r($data_string);
// set up the curl resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.testsite.com/sync1.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
));
$output = curl_exec($ch);
$output = curl_exec($ch);
if ($output === false) {
$info = curl_getinfo($ch);
curl_close($ch);
die('error occured during curl exec. Additioanl info: ' .var_export($info));
} //every time its going to print the "error occured during curl exec.additional info
curl_close($ch);
$decoded = json_decode($output);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}
var_export($decoded->response);
若要接收sync1.php我已經編寫這樣的,但數據來的數據,不知道爲什麼:
$result_data = json_decode($output, TRUE);
$len = $result_data['length'];
$serialNo = $result_data['serialNo'];
$customerName = $result_data['customerName'];
$phoneNo = $result_data['phoneNo'];
$mail = $result_data['mail'];
$customerPincode = $result_data['customerPincode'];
$customerCity = $result_data['customerCity'];
$customerState = $result_data['customerState'];
$warrantyStatus = $result_data['warrantyStatus'];
$productDescription= $result_data['productDescription'];
$serviceType = $result_data['serviceType'];
$typeOfRepair = $result_data['typeOfRepair'];
$productFamily = $result_data['productFamily'];
$serv_charges = $result_data['serv_charges'];
$problemReported = $result_data['problemReported'];
$techComment = $result_data['techComment'];
$createdUser = $result_data['createdUser'];
$location = $result_data['location'];
$reloc = $result_data['rloc'];
如何發送和接收數據,任何人都可以提供幫助?
說明什麼錯誤,請,因爲'「只有它給錯誤」'是不是很描述 – RamRaider
在執行sync.php這是發送數據到sync1.php其給予錯誤「在curl執行期間發生錯誤Additioanl info:」,$ output === false這就是爲什麼上述錯誤即將到來,爲什麼它給$輸出false沒有得到完全。 – Ashish
這基本上就是你在代碼中所擁有的 - 錯誤輸出包含什麼內容? – RamRaider