gpt4 book ai didi

c++ - curl_easy_perform() 失败 : Couldn't connect to server

转载 作者:搜寻专家 更新时间:2023-10-31 01:30:43 26 4
gpt4 key购买 nike

所以我在 C++ 中使用 libcurl 来检索页面中的数据,但由于某种原因,当我连接到我的 vps 时,它会在帖子标题中抛出错误。 vps 中的代码只是发出一个获取请求并从我的数据库中吐出一些数据。

#include "requestMapper.hpp"

// Send a GET request to API to retreive image
void RequestMapper::retreiveData(std::string url) {
CURL *curl;
CURLcode res;

curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
ISSUE HERE // curl_easy_setopt(curl, CURLOPT_URL, "https://104.236.200.91/index.php/food/");
res = curl_easy_perform(curl);
#ifdef SKIP_PEER_VERIFICATION
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
#endif
#ifdef SKIP_HOSTNAME_VERIFICATION
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif
res = curl_easy_perform(curl);
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
curl_global_cleanup();
}

// Submit a post request to API link to send data
void RequestMapper::postData() {

}


int main(void) {
RequestMapper rm;
rm.retreiveData("sample");
return 0;
}

当 url 类似于“https://google.com”时,这段代码工作正常,但是当我点击我设置的网络服务器的链接时,我得到了那个错误。我是这个图书馆的新手,但我认为我做的是正确的。如果有人有任何见解,请告诉我!我会继续改进这个问题,如果我找到解决方案,我会在这里分享。

谢谢!

编辑:

我最近解决了这个问题,并想与可能偶然发现这篇文章的任何人分享。我使用的是 https://URL 而我本应该使用 http://URL 所以如果您遇到这个问题请先尝试使用它!

最佳答案

这是错误 7,“无法连接到主机”described in the curl book像这样:

Failed to connect to host. curl managed to get an IP address to the machine and it tried to setup a TCP connection to the host but failed. This can be because you have specified the wrong port number, entered the wrong host name, the wrong protocol or perhaps because there is a firewall or another network equipment in between that blocks the traffic from getting through.

关于c++ - curl_easy_perform() 失败 : Couldn't connect to server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47214579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com