2013-04-10 102 views
0

我在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)式(未知)

布爾(假)

任何的幫助

回答

3

將此選項放入curl中並嘗試,可以它爲你工作

curl_setopt($s, CURLOPT_SSL_VERIFYPEER, false); 

欲瞭解更多信息請參閱curl_setopt

+1

感謝@Venu :) – 2013-04-10 06:20:33

+0

感謝周杰倫Hardia你的建議的作品 – User42590 2013-04-10 06:21:56