Curl and Https, "Cannot Resolve Host"

CURL and HTTPS, Cannot resolve host

Maybe a DNS issue?

Try your URL against this code:

$_h = curl_init();
curl_setopt($_h, CURLOPT_HEADER, 1);
curl_setopt($_h, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($_h, CURLOPT_HTTPGET, 1);
curl_setopt($_h, CURLOPT_URL, 'YOUR_URL' );
curl_setopt($_h, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
curl_setopt($_h, CURLOPT_DNS_CACHE_TIMEOUT, 2 );

var_dump(curl_exec($_h));
var_dump(curl_getinfo($_h));
var_dump(curl_error($_h));

Curl says it cannot resolve host but host can be resolved

Because you have not specified a host. The host is specified as a request command (part of -X arg).

You need to have (note the placement of single quote)

curl -X GET 'https://www.mywebsite.com/Web2/PDF.aspx?page=1' ...

curl: could not resolve host

If NOT on Windows, the answer above by @Necklondon with the single quotes should work.

If on Windows, however, you'll need to escape the double quotes within the JSON string.

curl -iX PUT -H "Content-Type: application/json" -d "{""name"": ""test number 1"",""description"": ""A website test"",""category"": ""test"",""release_date"": ""2017-10-08T01:01:00.776594Z""}" http://localhost:8000/home/search/3

In addition, to illustrate how much simpler the CURL command becomes when using a separate file for your JSON...

C:\Users\...\Desktop>TYPE somefile.json
{
"name": "test number 1",
"description": "A website test",
"category": "test",
"release_date": "2017-10-08T01:01:00.776594Z"
}

C:\Users\...\Desktop>curl -iX PUT -H "Content-Type: application/json" --data-binary @somefile.json http://localhost:8000/home/search/3

cURL gives Couldn't resolve host

Your code is OK. This is actually an DNS configuration problem on the dedicated server. Check that your hosting service permits outgoing curl connections.

Could not resolve host error with curl_multi on cURL version 7.64

I have the exact same issue: https://github.com/amazeeio/lagoon/issues/923

This is a curl regression: https://github.com/curl/curl/issues/3629 - which has been solved since opening the bug.

Thanks for the awesome test scripts :)



Related Topics



Leave a reply



Submit