我遇到的问题是" 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
)
请求成功。我发现它打印为null很奇怪。有什么帮助吗?
答案 0 :(得分:2)
添加
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);