php + curl issue Resource id # 2 on curl_init
php+curl在curl_init上发布资源id 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 | $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'; } |
我做错什么了?
尝试使用OP曲_错误美元(CH)和回波的diagnose的错误 </P >
1 2 3 4 5 6 7 8 9 10 11 12 13 | $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); |
如果你是不是一个主机与SSL你应该旁路的SSL验证 </P >
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?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'; } |
看到http:/ / / /我php.net手册/ function.curl-init.php </P >
你要试着这样的东西 </P >
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $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'; } |