1
可能重複:
curl_exec printing results when I don't want too爲什麼「curl_exec」打印「null」?
我有一個問題,即功能 「curl_exec」 打印文本到屏幕上。這裏是我的代碼:
$ch = curl_init("https://go.urbanairship.com/api/push/");
if ($ch) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "***:***"); // omitted
curl_setopt($ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"device_tokens": ["' . $device_token . '"], "aps": {"alert": "Hello! fucker!"}}');
curl_exec($ch);
}
呼喚:print_r(curl_getinfo($ch));
curl_exec($ch);
後給出。
Array ([url] => https://go.urbanairship.com/api/push/
[content_type] => application/json; charset=utf-8
[http_code] => 200
[header_size] => 222
[request_size] => 327
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.111714
[namelookup_time] => 0.029124
[connect_time] => 0.036017
[pretransfer_time] => 0.065684
[size_upload] => 0 [size_download] => 4
[speed_download] => 35
[speed_upload] => 0
[download_content_length] => 4
[upload_content_length] => 0
[starttransfer_time] => 0.111686
[redirect_time] => 0
)
請求成功。我覺得奇怪的是它打印出空白。任何幫助?
打印到標準輸出是其運作的古怪的默認模式。你需要['_RETURNTRANSFER'](http://php.net/manual/en/function.curl-exec.php)。 – mario 2012-01-28 19:42:39