1. <small id='QbMwl'></small><noframes id='QbMwl'>

      • <bdo id='QbMwl'></bdo><ul id='QbMwl'></ul>

    2. <tfoot id='QbMwl'></tfoot>

        <i id='QbMwl'><tr id='QbMwl'><dt id='QbMwl'><q id='QbMwl'><span id='QbMwl'><b id='QbMwl'><form id='QbMwl'><ins id='QbMwl'></ins><ul id='QbMwl'></ul><sub id='QbMwl'></sub></form><legend id='QbMwl'></legend><bdo id='QbMwl'><pre id='QbMwl'><center id='QbMwl'></center></pre></bdo></b><th id='QbMwl'></th></span></q></dt></tr></i><div id='QbMwl'><tfoot id='QbMwl'></tfoot><dl id='QbMwl'><fieldset id='QbMwl'></fieldset></dl></div>
        <legend id='QbMwl'><style id='QbMwl'><dir id='QbMwl'><q id='QbMwl'></q></dir></style></legend>

        C++ 中的 Curl - 无法从 HTTPS 获取数据

        时间:2024-08-14
          <bdo id='deym1'></bdo><ul id='deym1'></ul>
            <tfoot id='deym1'></tfoot>
          • <small id='deym1'></small><noframes id='deym1'>

              <legend id='deym1'><style id='deym1'><dir id='deym1'><q id='deym1'></q></dir></style></legend>

                  <tbody id='deym1'></tbody>
                1. <i id='deym1'><tr id='deym1'><dt id='deym1'><q id='deym1'><span id='deym1'><b id='deym1'><form id='deym1'><ins id='deym1'></ins><ul id='deym1'></ul><sub id='deym1'></sub></form><legend id='deym1'></legend><bdo id='deym1'><pre id='deym1'><center id='deym1'></center></pre></bdo></b><th id='deym1'></th></span></q></dt></tr></i><div id='deym1'><tfoot id='deym1'></tfoot><dl id='deym1'><fieldset id='deym1'></fieldset></dl></div>

                  本文介绍了C++ 中的 Curl - 无法从 HTTPS 获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我尝试使用代码从 HTTPS 获取数据时

                  When I trying to get data from HTTPS with code

                  static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
                  {
                      ((std::string*)userp)->append((char*)contents, size * nmemb);
                      return size * nmemb;
                  }
                  
                  string* NetIO::getUrlContent(string URL) {
                  
                      CURL *curl;
                      CURLcode res;
                      string *s = new string("");
                  
                      curl = curl_easy_init();
                      if (curl) {
                          //curl_easy_setopt(curl, CURLOPT_URL, URL);         
                          curl_easy_setopt(curl, CURLOPT_URL, "https://ya.ru/");
                          curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
                          curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
                          curl_easy_setopt(curl, CURLOPT_WRITEDATA, s);
                          res = curl_easy_perform(curl);
                          curl_easy_cleanup(curl);
                  
                      }
                  
                      return s;
                  }
                  

                  它无法接收 HTTPS 响应的内容并将其写入 s 变量 - s 包含".但是,如果我将 URL 更改为 HTTP - 此代码运行良好,并且 s 包含页面的 HTML 代码.

                  It can't receive content of HTTPS response and write it to the s variable - s contains "". But if I change URL to HTTP - this code works very well and s contains HTML code of the page.

                  curl_easy_setopt(curl, CURLOPT_URL, "http://tatarstan.shop.megafon.ru/");
                  

                  如何解决这个问题?

                  谢谢!

                  更新:如果我添加

                  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
                  

                  我的代码运行良好.为什么没有 CURLOPT_SSL_VERIFYPEER=0 就不能工作?

                  Than my code works well. Why it can't work without CURLOPT_SSL_VERIFYPEER=0?

                  我有一些 Visual Studio 解决方案.它包含 2 个项目 - libcurl,使用设置编译:

                  I have some Visual Studio solution. It contains 2 project - libcurl, that compiled with settings:

                  和第二个项目,这取决于 libcurl 项目:

                  and second project, that depends on libcurl project:

                  推荐答案

                  已解决!感谢@hank!

                  Solved! Thanks to @hank!

                  我的解决方案是:

                  1) 在 Google Chrome 中打开您的网站,打开证书信息.

                  1) Open your site in Google Chrome, open certificate info.

                  2) 将其及其每个父证书导出为 X.509.将证书文件合并为一个证书文件 - 制作证书链.

                  2) Export it and each of his parent certs as X.509. Concat cert files into the one cert file - make cert chain.

                  3) 使用带有代码的证书链的文件

                  3) Use file with cert chain with the code

                  curl_easy_setopt(curl, CURLOPT_CAINFO, "c:\Art\Projects\LifeSimLauncher\MyStaticLib\lifesim.biz.crt.cer");
                  

                  这篇关于C++ 中的 Curl - 无法从 HTTPS 获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Windows 中使用 MinGW 构建 OpenSSL? 下一篇:如何将证书字符串转换为 X509 结构.?

                  相关文章

                    <small id='nezTP'></small><noframes id='nezTP'>

                    <i id='nezTP'><tr id='nezTP'><dt id='nezTP'><q id='nezTP'><span id='nezTP'><b id='nezTP'><form id='nezTP'><ins id='nezTP'></ins><ul id='nezTP'></ul><sub id='nezTP'></sub></form><legend id='nezTP'></legend><bdo id='nezTP'><pre id='nezTP'><center id='nezTP'></center></pre></bdo></b><th id='nezTP'></th></span></q></dt></tr></i><div id='nezTP'><tfoot id='nezTP'></tfoot><dl id='nezTP'><fieldset id='nezTP'></fieldset></dl></div>

                  1. <legend id='nezTP'><style id='nezTP'><dir id='nezTP'><q id='nezTP'></q></dir></style></legend>

                    1. <tfoot id='nezTP'></tfoot>
                        <bdo id='nezTP'></bdo><ul id='nezTP'></ul>