卷曲给结果失败

时间:2013-04-10 06:08:34

标签: php

我在php的服务器端工作。最初测试此代码:

    $apiKey = "";


$registrationIDs = array( "" );


$message = "hello";


$url = 'https://android.googleapis.com/gcm/send';


$fields = array(
                'registration_ids'  => $registrationIDs,
                'data'              => array( "message" => $message ),

                );


$headers = array( 
                    'Authorization: key=' . $apiKey,
                    'Content-Type: application/json'

                );



$ch = curl_init();


$u=curl_setopt( $ch, CURLOPT_URL, $url );


$p=curl_setopt( $ch, CURLOPT_POST, true );

$f=curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$h=curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);

$t=curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

$c=curl_setopt($ch, CURLOPT_VERBOSE, true);

$j=curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );


$result = curl_exec($ch);

 $responseInfo    = curl_getinfo($ch);
   $header_size    = curl_getinfo($ch, CURLINFO_HEADER_SIZE); 
   $responseHeader = substr($result , 0, $header_size);
   $responseBody   = substr($result , $header_size);

    echo 'Header: <br>'. $responseHeader;
    echo 'Body: <br>'. $responseBody;


curl_close($ch);

var_dump($ch);

var_dump($result);

but on :

var_dump($ch);

var_dump($result);

浏览器给出:

  

部首:   正文:类型(未知)的资源(2)

     

布尔(假)

任何帮助

1 个答案:

答案 0 :(得分:3)

将此选项放入curl并尝试,可能适用于您

curl_setopt($s, CURLOPT_SSL_VERIFYPEER, false);

有关详细信息,请参阅curl_setopt