将cURL命令行转换为PHP cURL

编程入门 行业动态 更新时间:2024-10-28 09:16:57
本文介绍了将cURL命令行转换为PHP cURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要将此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

本文发布于:2023-06-05 01:24:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/508989.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   命令行   cURL   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!