2016-06-01 14 views
0

PHP + curl_initのカール問題リソースID#2:PHP + curl_initのカール問題リソースID#2

 
$url = "https://example.com:4433/deviceservice/authorize?login=query"; // URL JSON 
     $ch = curl_init($url); 
     echo $ch; //write Resource id # 2 
     if($ch) 
     { 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, TRUE); 
      $json = curl_exec($ch); 
      $json = json_decode($json); 
     } else { 
      echo 'nothing'; 
      } 

私が間違って何をしているのですか?

+0

Googleにこの手順を実行してください。私はあなたがそれを理解することができると確信しています。 – Vickrant

答えて

1

curl_initは、成功した場合はcURL、エラーの場合は偽を返します。 したがって、echo $ch;は、リソースID#2のようなものを返します。

はあなたがSSLを持つホスト上に存在しない場合は、使用する

<?php 
    $url = "https://example.com:4433/deviceservice/authorize?login=query"; 
    $ch = curl_init($url); 
    echo $ch; //write Resource id # 2 
    if($ch) 
    { 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
     $json = curl_exec($ch); 
     $json = json_decode($json); 
    } else { 
     echo 'nothing'; 
    } 
1

のようなものを試してみて

http://php.net/manual/en/function.curl-init.phpを参照してください。エラーを診断するcurl_error($ ch)とエコー

$ch= curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
)                  
);  

$response = curl_exec($ch); 
$err_status = curl_error($ch); 
echo $err_status; 
curl_close($ch); 
2

てみSSL検証をバイパスする必要がありますので、この

$url = "https://example.com:4433/deviceservice/authorize?login=query"; // URL JSON 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, TRUE); 
$json = curl_exec($ch); 
$json = json_decode($json); 
curl_close($ch); 

if(empty($json)){ 
    echo 'nothing'; 
}