-5
我使用下面的這段代碼通過一個URL將數據發送到另一臺服務器,並且它可以成功工作。我想捕獲服務器的響應並進行處理,但我似乎無法捕獲它。如何捕獲CURL的響應
CODE
$url="http://www.example.com/com_spc/api.php?username=".urlencode($uname)."&password=".urlencode($pwd);
$ch = curl_init(); // create cURL handle (ch)
if (!$ch) {
die("Couldn't initialize a cURL handle");
}
// set some cURL options
$ret = curl_setopt($ch, CURLOPT_URL, $url);
$ret = curl_setopt($ch, CURLOPT_HEADER, 0);
$ret = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
$ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$ret = curl_setopt($ch, CURLOPT_TIMEOUT, 30);
// execute
$ret = curl_exec($ch);
if (empty($ret)) {
// some kind of an error happened
die(curl_error($ch));
curl_close($ch); // close cURL handler
} else {
$info = curl_getinfo($ch);
curl_close($ch); // close cURL handler
if (empty($info['http_code'])) {
die("No HTTP code was returned");
} else {
}
}
您已設置'CURLOPT_RETURNTRANSFER'到'0'。這就是爲什麼你沒有得到結果內容。 – mario
只需正確閱讀文檔,不要隨意設置選項... – MueR
@MueR LOL如此真實...... – mate64