Curl简单的https请求不返回任何C++

Gre*_*ego 3 c++ curl

我正在使用Visual Studio C++ 2010,它与cURL一起工作正常,但问题是https请求什么都不返回.而不是显示输出:

#include "StdAfx.h"
#include <stdio.h>
#include <curl/curl.h>
#include <conio.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.com");
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  _getch();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

例如,此代码只是对Google的https请求,但它不会返回任何内容,因为它以https开头.如果我拿走https的"s",它就可以正常工作:"http://www.google.com.br"通常会显示结果.我在这里想念的是什么?我正在使用cURL中的示例.我尝试过与其他网站同样的事情发生了.:/ /像https://www.facebook.com

顺便说一句,如果你们知道如何将网页内容存储在一个字符串中,我很高兴知道.

提前致谢.:)

use*_*525 6

这个简单的例子对我有用:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    /* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */
    curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.co.uk");

    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我很久以前就得到了源代码并构建了库,但我确信在编译源代码之前我已经启用了SSL支持.确保安装了OpenSSL并且(如果您在Linux下工作),您可以PKG_CONFIG_PATH正确初始化变量.这些是您在执行configure脚本时指定的两个选项.

  --with-ssl=PATH         Where to look for OpenSSL, PATH points to the SSL
                          installation (default: /usr/local/ssl); when
                          possible, set the PKG_CONFIG_PATH environment
                          variable instead of using this option

  --without-ssl           disable OpenSSL
Run Code Online (Sandbox Code Playgroud)

我希望它有所帮助.

如果您使用的是Windows,这篇文章对您也很有用:

在Windows上使用SSL支持构建libcurl