[英]Curl unable to get local issuer certificate with Filckr API in PHP
Since Flickr API fully supports SSL, I did the steps following 由于Flickr API完全支持SSL,因此我执行了以下步骤
Download .pem file from http://curl.haxx.se/ca/cacert.pem , rename it to curl- 从http://curl.haxx.se/ca/cacert.pem下载.pem文件,将其重命名为curl-
ca-bundle.crt, and copy to C:/xampp/php/ (I'm using XAMPP on Win8) ca-bundle.crt,然后复制到C:/ xampp / php /(我在Win8上使用XAMPP)
Add cacert location to my code 将cacert位置添加到我的代码中
curl_setopt($ch, CURLOPT_CAINFO, "C:/xampp/php/curl-ca-bundle.crt");
Here's all my PHP code 这是我所有的PHP代码
<?php
$url = 'https://api.flickr.com/services/rest/
?method=flickr.people.findByUsername
&api_key=38f6b424cbcaeb07967dc7732ddb3f32
&username=Sami';
$ca = 'C:/xampp/php/curl-ca-bundle.crt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CAINFO, $ca);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
echo $result;
?>
And then I got 然后我得到了
Curl error: SSL certificate problem: unable to get local issuer certificate
Please give me some suggestions or another way to solve local certificate issue on Flickr API. 请给我一些建议或其他方法来解决Flickr API上的本地证书问题。
I would suggest that you include a couple of extra parameters in your curl call as you are fetching from an https source - namely:- 我建议您在从https源中获取卷曲时在curl调用中包括几个额外的参数,即:-
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 1 );
and maybe also a useragent as I have found many api calls get blocked for not having a useragent 也许还有一个useragent,因为我发现许多api调用由于没有useragent而被阻止
curl_setopt( $ch, CURLOPT_USERAGENT, 'flickr-curl-fetcher' );
Also I noticed ( after properly reading your post ) that the cacert.pem should be renamed? 我也注意到(正确阅读您的帖子后),cacert.pem应该重命名吗? This doesn't seem right - I use the following and it works.
这似乎不太正确-我使用以下方法,它可以正常工作。
curl_setopt( $ch, CURLOPT_CAINFO, realpath( 'c:/wwwroot/cacert.pem' ) );
/* Full code that does return XML */
$url = 'https://api.flickr.com/services/rest/?method=flickr.people.findByUsername&api_key=38f6b424cbcaeb07967dc7732ddb3f32&username=Sami';
$ca = 'C:/xampp/php/cacert.pem';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_HEADER, 0 );
curl_setopt($ch, CURLOPT_CAINFO, realpath($ca) );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 1 );
curl_setopt( $ch, CURLOPT_USERAGENT, 'flickr-curl-fetcher' );
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
curl_close( $ch );
print_r( $result );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.