0

I'm using curl-7.64.1 (https://curl.haxx.se/windows/) 32 bit, with OpenSSL 1.1.1b (32 bit) and tidy-5.0.0 for XML parsing.

When I'm home making any connection work fine, but when I'm at School, connected to the Wifi of this one. All the connection are refused.

I tried to make a connection to https://www.google.fr/ and with CURLOPT_VERBOSE I get on the screen the message :

  • Trying 172.217.18.227...
  • TCP_NODELAY set
  • connect to 172.217.18.227 port 443 failed: Connection refused
  • Failed to connect to www.google.fr port 443: Connection refused
  • Closing connection 0 Failed to connect to www.google.fr port 443: Connection refused

I tried first to change the port, to 8080. I wrote https://www.google.fr:8080 as URL for libCurl. But still have : Failed to connect to www.google.fr port 8080: Connection refused

After I tried to setup a proxy in the LibCurl connection. But it didn't change anything.

 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);

I would like make the connection work on the Wifi of my School.

EDIT 1 :

Following the advise in this post : Can servers block curl requests?

I exacted the headers from Chrome and added it into 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);

I enable the UserAgent settings :

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");

And I added cookies :

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

But after all the connection still failed.

axel7083
  • 571
  • 3
  • 16
  • Why did you append port 8080 to the URL? https://www.google.fr:8080 Google does not listen on port 8080. – ikkentim Apr 17 '19 at 08:01

1 Answers1

1

If your connection is fine, this error is probably due to a proxy server: is your school using a proxy?

If so, you need to explicitely tell curl to make this request through your proxy. This can be done with

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

You can find more informations on proxy there: https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html

Alternatively, you can try to use this in command line with curl -x http://proxy_server:proxy_port --proxy-user username:password -L http://url

Maxime B.
  • 1,116
  • 8
  • 21
  • Hey, yes you were right, my school is using a proxy. Thanks to the post https://superuser.com/questions/346372/how-do-i-know-what-proxy-server-im-using I get the proxy of the server and add it into the configuration of the connection of curl, and now It work fine. – axel7083 Apr 17 '19 at 08:29
  • @axel7083 You already used a proxy in your question. What did you need to change to make it work? Was ist just the wrong port or something else? – Gerhardh Apr 17 '19 at 10:36
  • This particular line was added in an edit and was not in the original post. – Maxime B. Apr 17 '19 at 11:39
  • This line was already present in first revision: "After I tried to setup a proxy in the LibCurl connection. But it didn't change anything." – Gerhardh Apr 17 '19 at 13:36
  • In fact I was using a random proxy, not the proxy of my school, so I used some tools to get the proxy of my school and after using it, it was working fine – axel7083 Apr 25 '19 at 19:16