沉默输出curl_setopt_array

时间:2015-06-09 16:04:08

标签: php curl

为了向用户发送Boxcar通知,我使用此示例:

curl_setopt_array(
    $chpush = curl_init(),
    array(
        CURLOPT_URL => "https://new.boxcar.io/api/notifications",
        CURLOPT_POSTFIELDS => array(
            "user_credentials" => 'ACCESS_TOKEN',
            "notification[title]" => 'message title',
            "notification[long_message]" => '<b>Some text or HTML for the full layout page notification</b>',
            "notification[sound]" => "bird-1",
        )));
$ret = curl_exec($chpush);
curl_close($chpush);

但是我的页面上有一些输出,这可能是Boxcar服务器的响应。如何防止打印输出?

1 个答案:

答案 0 :(得分:0)

我已经找到了解决方案:

CURLOPT_RETURNTRANSFER设为TRUE。有关详细信息,请参阅this StackOverflow答案。为了将来参考,要向用户发送Boxcar通知,您还可以使用:

$chpush = curl_init();
$boxcarData = array(
        "user_credentials" => 'ACCESS_TOKEN',
        "notification[title]" => 'message title',
        "notification[long_message]" => '<b>Some text or HTML for the full layout page notification</b>',
        "notification[sound]" => "bird-1",
);
curl_setopt($chpush, CURLOPT_URL, "https://new.boxcar.io/api/notifications");
curl_setopt($chpush, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($chpush, CURLOPT_POSTFIELDS, $boxcarData);
$ret = curl_exec($chpush);
curl_close($chpush);