0
我很困惑,爲什麼$響應不返回任何東西,我是新來的捲曲請大家幫忙,爲什麼PHP + curl,HTTP POST請求返回null?
$post = [
'AreaCode' => '02',
'PhoneNumber' => '33312733',
'InquiryBy' => 'telephone',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://billing.te.eg/api/Account/Inquiry');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json',
'Access-Control-Allow-Origin: *',
));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE);
$response = curl_exec($ch);
if ($response === false) $response = curl_error($ch);
echo stripslashes($response);
curl_close($ch);
而郵遞員
你的數據不會自動成爲JSON,只是因爲你設置Content-Type頭這樣說。將一個數組傳遞給CURLOPT_POSTFIELDS將導致它創建一個類似查詢字符串的格式,name1 = value1&name2 = value2&...傳遞一個JSON字符串。 – CBroe