我需要将此cURL命令翻译成PHP cURL代码:
I need to translate this cURL command into PHP cURL code:
> curl --get 'api.twitter/1/followers/ids.json' --data > 'cursor=-1&screen_name=somename' --header 'Authorization: OAuth > oauth_consumer_key="key", oauth_nonce="nonce", > oauth_signature="signature", oauth_signature_method="HMAC-SHA1", > oauth_timestamp="timestamp", oauth_token="token", oauth_version="1.0"' > --verbose
似乎工作:
> $ch = curl_init(); > curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: OAuth oauth_consumer_key="key", oauth_nonce="nonce", oauth_signature="signature", oauth_signature_method="HMAC-SHA1", oauth_timestamp="timestamp", oauth_token="token", oauth_version="1.0"')); > curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); > curl_setopt($ch, CURLOPT_VERBOSE, 1); > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); > curl_setopt($ch, CURLOPT_HTTPGET, 1); > curl_setopt($ch, CURLOPT_URL, 'api.twitter/1/users/show.json?cursor=-1&screen_name=somename'); > $page = curl_exec($ch); > curl_close($ch);错误我得到了
SSL证书问题,请验证CA证书是否正确。详细信息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败
SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
但是它适用于标准curl命令
however it works in the standard curl command
推荐答案您需要为证书链提供curl,以允许它将Twitter的SSL证书验证为有效。为此,请从此处下载必要的证书签名从此处,并将其保存到一个普通文件(我会假设你命名为 cacert.pem )。
You need to provide curl with the certificate chain that will allow it to verify Twitter's SSL certificate as valid. To do this, download the requisite certificate signatures from here and save them into a plain file (I 'll assume you name it cacert.pem).
,将 CURLOPT_CAINFO 设置为指向此文件:
Then, before making the request, set CURLOPT_CAINFO to point to this file:
// assumes file in same directory as script curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');这也是一个好主意,明确启用SSL证书验证,而不是依赖于默认设置:
It's also a good idea to explicitly enable SSL certificate verification instead of relying on default settings:
curl_setopt($ch, CURLOPT_VERIFYPEER, true);更多推荐
将cURL命令行转换为PHP cURL
发布评论