如何使用cURL和PHP从使用SSL的网站获取数据? [英] How to get data from a website that uses SSL using cURL and PHP?

查看:62
本文介绍了如何使用cURL和PHP从使用SSL的网站获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从一个网站上获取一些数据,您需要拥有一个SSL证书才能连接到该网站.我发现以下代码:

I am trying to get some data from a website where you need to have a SSL certificate to be able to connect to it. I have found the following code :

// create curl resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, $host);

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $host);

// $output contains the output string
$output = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch);

cURL查询效果很好,但是我得到的数据是这个:

The cURL query works well, but the data that I get is this one :

400之前没有所需的SSL证书发送

400错误请求

没有所需的SSL证书已发送
nginx
400 No required SSL certificate was sent

400 Bad Request

No required SSL certificate was sent
nginx

我要寻找的是网站的index.php(以及其他路径)中包含的数据.因此,我该怎么做才能在代码中添加证书,并使用cURL从网站获取数据?PS:数据将采用JSON格式吗?PPS:如果这有帮助,我正在使用PHPStorm

What I am looking for is the data contained in the index.php (and the other paths) of the website. So, how can I do to add a Certificate to the code, and, using cURL, get the data from the website ? PS : Will the data will be in JSON format ? PPS : if this can be helpfull, I am using PHPStorm

推荐答案

您可以尝试这样吗?echo $ str = file_get_contents(" https://jsonplaceholder.typicode.com/todos/1");

can you try like this? echo $str = file_get_contents("https://jsonplaceholder.typicode.com/todos/1");

这篇关于如何使用cURL和PHP从使用SSL的网站获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆