[英]curl_easy_perform() failed: Couldn't connect to server
所以我在C ++中使用libcurl檢索頁面中的數據,但是由於某些原因,當我連接到vps時,它將在帖子標題中引發錯誤。 vps中的代碼只是發出一個get請求,並從數據庫中吐出一些數據。
#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;
}
當網址類似“ https://google.com ”時,此代碼可以正常工作,但是當我單擊指向我的Web服務器的鏈接時,我設置了該錯誤。 我是這個庫的新手,但我認為自己做的正確。 如果有人有任何見解,請告訴我! 我將繼續對此進行修改,如果找到解決方案,請在此處分享。
謝謝!
編輯:
我最近解決了這個問題,並希望與可能偶然發現此帖子的任何人分享。 我當時使用的是https://URL
,而我應該一直使用的是http://URL
所以如果您遇到此問題,請先嘗試使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.