Libcurl:无法连接到www.google.fr连接被拒绝

问题描述 投票:0回答:1

我正在使用curl-7.64.1(https://curl.haxx.se/windows/)32位,使用OpenSSL 1.1.1b(32位)和tidy-5.0.0进行XML解析。

当我在家做任何连接工作正常,但当我在学校时,连接到这个的Wifi。所有的连接都被拒绝了。

我尝试连接到https://www.google.fr/并使用CURLOPT_VERBOSE我在屏幕上显示以下消息:

  • 尝试172.217.18.227 ......
  • TCP_NODELAY设置
  • 连接到172.217.18.227端口443失败:连接被拒绝
  • 无法连接到www.google.fr端口443:连接被拒绝
  • 关闭连接0无法连接到www.google.fr端口443:连接被拒绝

我首先尝试将端口更改为8080.我将https://www.google.fr:8080写为libCurl的URL。但仍有:无法连接到www.google.fr端口8080:连接被拒绝

我尝试在LibCurl连接中设置代理后。但它没有改变任何东西。

 CURL *curl;
 char curl_errbuf[CURL_ERROR_SIZE];
 TidyDoc tdoc;
 TidyBuffer docbuf = {0};
 TidyBuffer tidy_errbuf = {0};
 int err;

 curl = curl_easy_init();
 curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.fr:8080");
 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
 //curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);

 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);

 tdoc = tidyCreate();
 tidyOptSetBool(tdoc, TidyForceOutput, yes);
 tidyOptSetInt(tdoc, TidyWrapLen, 4096);
 tidySetErrorBuffer(tdoc, &tidy_errbuf);
 tidyBufInit(&docbuf);

 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf);

 curl_easy_setopt(curl, CURLOPT_PROXY, "http://212.129.52.155:8080");

 err = curl_easy_perform(curl);

我想在我学校的Wifi上进行连接。

EDIT 1 :

遵循这篇文章的建议:Can servers block curl requests?

我从Chrome中删除了标题并将其添加到LibCurl中。

struct curl_slist *list = NULL;

list = curl_slist_append(list, "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
list = curl_slist_append(list, "accept-encoding: gzip, deflate, br");
list = curl_slist_append(list, "accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7");
list = curl_slist_append(list, "cache-control: max-age=0");
list = curl_slist_append(list, "upgrade-insecure-requests: 1");

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);

我启用了UserAgent设置:

curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36");

我添加了cookie:

curl_easy_setopt(curl, CURLOPT_COOKIESESSION, 1L);
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookies.txt");

但毕竟连接仍然失败。

c codeblocks libcurl
1个回答
1
投票

如果您的连接正常,则此错误可能是由于代理服务器:您的学校是否使用代理?

如果是这样,您需要明确告诉curl通过您的代理发出此请求。这可以通过以下方式完成

curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");

您可以在那里找到有关代理的更多信息:https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html

或者,您可以尝试在命令行中使用curl -x http://proxy_server:proxy_port --proxy-user username:password -L http://url

© www.soinside.com 2019 - 2024. All rights reserved.