C++;HTTPS请求使用cURL 7.55.1失败

C++;HTTPS请求使用cURL 7.55.1失败,curl,c++17,libcurl,Curl,C++17,Libcurl,我只是想从页面上获取数据。在这个测试示例中,它应该返回一个数字。 在控制台中: * STATE: INIT => CONNECT handle 0x7011c8; line 1654 (connection #-5000) * Added connection 0. The cache now contains 1 members * STATE: CONNECT => WAITRESOLVE handle 0x7011c8; line 1700 (connection #0) *

我只是想从页面上获取数据。在这个测试示例中,它应该返回一个数字。 在控制台中:

* STATE: INIT => CONNECT handle 0x7011c8; line 1654 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x7011c8; line 1700 (connection #0)
* family0 == v4, family1 == v6
*   Trying 31.170.160.123:443...
* STATE: WAITRESOLVE => WAITCONNECT handle 0x7011c8; line 1782 (connection #0)
* Connected to www.atmaple.com (31.170.160.123) port 443 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x7011c8; line 1848 (connection #0)
* Marked for [keep alive]: HTTP default
* ALPN, offering http/1.1
* STATE: SENDPROTOCONNECT => PROTOCONNECT handle 0x7011c8; line 1866 (connection #0)
* SSL certificate problem: unable to get local issuer certificate
* Marked for [closure]: Failed HTTPS connection
* multi_done
* The cache now contains 0 members
* Closing connection 0
* Expire cleared (transfer 0x7011c8)
这是我使用的从vcpkg安装的版本:

curl --ssl https://www.atmaple.com/Test.txt
3,711,488
尝试添加SSL

curl --version
curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL
Release-Date: 2017-11-14, security patched: 2019-11-05
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL
#包括
#包括
#包括

所以,我做了一些搜索,找到了这个网站:

有一个叫做LibCurl with SSL的部分,他从这个网站下载了一个CA证书:

我下载了cacert.pem并将其重命名为ca_bundle.crt(或任何您想命名的名称,并将其添加到我的代码中:

#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/bio.h>
并从链接返回正确的数据

curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_easy_setopt(curl, CURLOPT_CAINFO, "ca-bundle.crt");
*状态:INIT=>连接句柄0x1174928;第1654行(连接#-5000)
*已添加连接0。缓存现在包含1个成员
*状态:CONNECT=>WAITRESOLVE句柄0x1174928;第1700行(连接#0)
*家族0==v4,家族1==v6
*正在尝试31.170.160.123:443。。。
*状态:WAITRESOLVE=>WAITCONNECT句柄0x1174928;第1782行(连接#0)
*已连接到www.atmaple.com(31.170.160.123)端口443(#0)
*状态:WAITCONNECT=>SENDPROTOCONNECT句柄0x1174928;第1848行(连接#0)
*标记为[保持活动]:HTTP默认值
*ALPN,提供http/1.1
*已成功设置证书验证位置:
*CAfile:ca-bundle.crt
*卡帕斯:没有
*状态:SENDPROTOCONNECT=>PROTOCONNECT句柄0x1174928;第1866行(连接#0)
*使用TLSv1.3/TLS_AES_256_GCM_SHA384的SSL连接
*ALPN,接受使用http/1.1的服务器
*服务器证书:
*主题:CN=atmaple.com
*开始日期:2月25日03:04:46格林尼治标准时间2021
*过期日期:5月26日03:04:46 2021 GMT
*主题名称:主机“www.atmaple.com”匹配证书的“www.atmaple.com”
*发卡机构:C=US;O=Let's Encrypt;CN=R3
*SSL证书验证正常。
*状态:PROTOCONNECT=>DO句柄0x1174928;第1885行(连接#0)
>GET/Test.txt HTTP/1.1
主持人:www.atmaple.com
接受:*/*
*状态:DO=>DO#u DONE句柄0x1174928;第1940行(连接#0)
*状态:DO#u DONE=>执行句柄0x1174928;第2061行(连接#0)
*将捆绑包标记为不支持多用途
*HTTP 1.1或更高版本,具有持久连接
DONE句柄0x1174928;第2251行(连接#0)
*多次完成
*0到主机www.atmaple.com的连接保持不变
*已清除过期(传输0x1174928)

3711488这并没有解决问题。尽管如此,我还是开始使用ca-bundle.crt,它从站点返回正确的数据。虽然,最初我不必这样做,这就是为什么我如此困惑的原因。
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_easy_setopt(curl, CURLOPT_CAINFO, "ca-bundle.crt");
* STATE: INIT => CONNECT handle 0x1174928; line 1654 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x1174928; line 1700 (connection #0)
* family0 == v4, family1 == v6
*   Trying 31.170.160.123:443...
* STATE: WAITRESOLVE => WAITCONNECT handle 0x1174928; line 1782 (connection #0)
* Connected to www.atmaple.com (31.170.160.123) port 443 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x1174928; line 1848 (connection #0)
* Marked for [keep alive]: HTTP default
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: ca-bundle.crt
*  CApath: none
* STATE: SENDPROTOCONNECT => PROTOCONNECT handle 0x1174928; line 1866 (connection #0)
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=atmaple.com
*  start date: Feb 25 03:04:46 2021 GMT
*  expire date: May 26 03:04:46 2021 GMT
*  subjectAltName: host "www.atmaple.com" matched cert's "www.atmaple.com"
*  issuer: C=US; O=Let's Encrypt; CN=R3
*  SSL certificate verify ok.
* STATE: PROTOCONNECT => DO handle 0x1174928; line 1885 (connection #0)
> GET /Test.txt HTTP/1.1
Host: www.atmaple.com
Accept: */*

* STATE: DO => DO_DONE handle 0x1174928; line 1940 (connection #0)
* STATE: DO_DONE => PERFORM handle 0x1174928; line 2061 (connection #0)
* Mark bundle as not supporting multiuse
* HTTP 1.1 or later with persistent connection
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Content-Type: text/plain
< Last-Modified: Tue, 27 Oct 2020 22:25:29 GMT
< Etag: "9-5f989e59-7aa76bf0011c68c2;;;"
< Accept-Ranges: bytes
< Content-Length: 9
< Date: Mon, 05 Apr 2021 23:39:30 GMT
< Server: LiteSpeed
< Content-Security-Policy: upgrade-insecure-requests
<
* STATE: PERFORM => DONE handle 0x1174928; line 2251 (connection #0)
* multi_done
* Connection #0 to host www.atmaple.com left intact
* Expire cleared (transfer 0x1174928)