curl_easy_perform() 失败:无法连接到服务器
curl_easy_perform() failed: Couldn't connect to server
所以我在 C++ 中使用 libcurl 来检索页面中的数据,但由于某种原因,当我连接到我的 [=31= 时,它会在 post 标题中抛出错误]. 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”时,这段代码工作正常,但是当我将 link 设置到我设置的网络服务器时,我得到了那个错误。我是这个图书馆的新手,但我认为我做的是正确的。如果有人有任何见解,请告诉我!我会继续修改这个,如果我找到解决方案,我会在这里分享。
谢谢!
编辑:
我最近解决了这个问题,并想与可能偶然发现此问题的任何人分享它 post。
我在使用 https://URL
而我应该使用 http://URL
所以如果你 运行 遇到这个问题请先尝试使用它!
这是错误 7,"couldn't connect to host" 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++ 中使用 libcurl 来检索页面中的数据,但由于某种原因,当我连接到我的 [=31= 时,它会在 post 标题中抛出错误]. 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”时,这段代码工作正常,但是当我将 link 设置到我设置的网络服务器时,我得到了那个错误。我是这个图书馆的新手,但我认为我做的是正确的。如果有人有任何见解,请告诉我!我会继续修改这个,如果我找到解决方案,我会在这里分享。
谢谢!
编辑:
我最近解决了这个问题,并想与可能偶然发现此问题的任何人分享它 post。
我在使用 https://URL
而我应该使用 http://URL
所以如果你 运行 遇到这个问题请先尝试使用它!
这是错误 7,"couldn't connect to host" 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.