【发布时间】:2016-03-22 21:31:36
【问题描述】:
我在使用 PHP API here 时遇到问题。它可以工作,但每第二次或第三次请求我都会收到以下错误:
无法完成请求。[SSL 连接错误]
这发生在 Vimeo.php:154 上。这是在 curl 执行之后。我尝试在命令行中单独使用 curl 并得到:
curl: (35) SSL 连接错误
此引用:
SSL/TLS 握手中出现问题。您真的需要错误缓冲区并在那里阅读消息,因为它可以稍微定位问题。可以是证书(文件格式、路径、权限)、密码等。
所以我用 PHP file_get_contents 尝试了它,我得到的警告是
警告:file_get_contents(): SSL: Connection reset by peer
我有点不知所措,不知道这是 VImeo 有时会拒绝我的请求还是服务器有时会失去连接。我试图找出是否有人以前遇到过这个问题,或者我可以使用一些步骤来获得更多关于导致问题的线索。这是我的代码
使用 file_Gets_contents
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Authorization: bearer <Personal access token>\r\n"
),
'ssl'=>array(
'allow_self_signed'=>false,
'verify_peer'=>false,
)
);
$context = stream_context_create($opts);
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$unparsed_json = file_get_contents($url, false, $context);
$json_object = json_decode($unparsed_json);
var_dump($json_object);die();
使用 CURL
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$curlHeader = [
'Authorization: bearer <Personal access token>',
'Accept: ' . self::VERSION_STRING,
];
$ch = curl_init();
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeader);
curl_setopt($ch, CURLOPT_HTTPGET, true);
$unparsed_json = curl_exec ($ch);
// Check if any error occurred
if(curl_errno($ch))
{
$info = curl_getinfo($ch);
var_dump('Curl error: ', curl_error($ch), ' Curl error no: ', curl_errno($ch), ' Unparsed json: ', $unparsed_json, ' Info: ', $info, 'DIR CERT: ', __DIR__ . '/CERT'); die();
}
curl_close ($ch);
$json_object = json_decode($unparsed_json);
var_dump($unparsed_json);die();
使用 Vimeo.php
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$client_id = '<Client ID>';
$client_secret = '<Secret>';
$lib = new Vimeo\Vimeo($client_id, $client_secret);
$lib->setToken('<Personal access token>');
$response = $lib->request($url, [], 'GET');
var_dump($response['body']);die();
我在 Linux 命令行的 curl 上使用了 verbose 并看到了这个:
关于 connect() 到 api.vimeo.com 端口 443 (#0)
正在尝试 104.156.85.217... 已连接
连接到 api.vimeo.com (104.156.85.217) 端口 443 (#0)
使用 certpath 初始化 NSS:sql:/etc/pki/nssdb
CAfile: '证书文件位置'
CApath:无
NSS 错误 -5961
关闭连接 #0
SSL 连接错误
curl: (35) SSL 连接错误
【问题讨论】:
标签: php curl https rhel vimeo-api