[英]Use curl with a webpage with no security protocol
我有一個網頁:10.1.1.165,我試圖從中獲取數據。 我已經在 linux 中構建了這個程序並且它運行良好,但是,在為 windows 系統開發時我遇到了一個問題。
if (filename.substr(filename.length() - 4, 4) == "html" || filename.substr(filename.length() - 3, 3) == "htm")
{
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
string s;
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, filename.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
if (gLogger->isDebug()) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout/1000);
//curl_easy_setopt (curl, CURLOPT_VERBOSE, 1L); //remove this to disable verbose output
// Perform the request, res will get the return code
res = curl_easy_perform(curl);
// Check for errors
if (res != CURLE_OK)
{
while (res == CURLE_OPERATION_TIMEDOUT)
{
res = curl_easy_perform(curl);
}
if (res != CURLE_OK)
{
gLogger->error("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
return -1;
}
}
curl_easy_cleanup(curl);
在我的 linux 系統上,這完美地工作。 在我的 Windows 系統上,我得到: curl_easy_perform() failed: Unsupported protocol。 如果我轉到我的網頁 10.1.1.165,我會看到它是在沒有安全性的情況下托管的。 我無法更改該網頁的托管方式。
根據此資源: https : //curl.haxx.se/libcurl/c/CURLOPT_PROTOCOLS.html
默認情況下,libcurl 將接受所有協議
有誰知道為什么 curl 不喜歡我在 Windows 上抓取這個網頁? 如果是這樣,我可能需要調整哪些設置?
我已經通過切換到 curl-7.55.1 解決了我的問題。 以前我使用 curl-7.68.0。 我不確定是否刪除了該功能,或者使用它是否更復雜。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.