Simple curl request is not working: "Could not resolve host"

I have a webiste hosted on ipage. My website is active on cloudflare. The following curl request fails.
The same curl request used to work with another site hosted on the same ipage with cloudflare. I am not sure why it stopped working recently. Any help would be appriciated.

$url = ‘https://pastebin.com/api/api_post.php’;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ‘api_option=paste&api_user_key=’.$api_user_key.’&api_paste_private=’.$api_paste_private.’&api_paste_name=’.$api_paste_name.’&api_paste_expire_date=’.$api_paste_expire_date.’&api_paste_format=’.$api_paste_format.’&api_dev_key=’.$api_dev_key.’&api_paste_code=’.$api_paste_code.’’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
var_dump(curl_exec($ch));
var_dump(curl_error($ch));

Response:
bool(false) string(36) “Could not resolve host: pastebin.com

Note: The same request is working in my local machine.

It would seem as if the server cannot resolve that hostname.

Whats the output of

<pre><?php
	var_dump([
		gethostbyname('pastebin.com'),
		gethostbyname('www.pastebin.com'),
		gethostbyname('cloudflare.com'),
		gethostbyname('www.cloudflare.com'),
		gethostbyname('google.com'),
		gethostbyname('www.google.com')
	]);
?>

Do you have SSH access?

Hi Sandro,

Thank you for helping me on this.

Here is the output:
array(6) {
[0]=>
string(12) “pastebin.com
[1]=>
string(16) “www.pastebin.com
[2]=>
string(14) “198.41.214.162”
[3]=>
string(12) “104.17.209.9”
[4]=>
string(13) “172.217.6.206”
[5]=>
string(13) “172.217.6.228”
}

I do not have an SSH access for this.

Yeah, it cannot resolve that host name. You need to contact your host for that.

So it is nothing to do with Cloudflare? My hosting was not able to help me with this.
I failed to explain the issue clearly to the hosting team. Can this example will explain the issue to the hosting team? Again, Thank you for helping me with this.

Nothing at all, thats purely hosting related.

Tell you host that you cannot resolve that host for whatever reason on their machine, whereas other hosts appear to work.

Thank you, Sandro.

I will contact the hosting team for this. :+1::+1:

1 Like

Hi @sandro,

I contacted my hosting provider on this issue. (https://www.ipage.com/)
They do understand the issue. But they didn’t know where exactly or how exactly to fix this. They don’t know whether any special configuration needs to be enabled to connect with pastebin.com

Here is their recent reply.

I was able to replicate the error at https://www.senthilprabu.in/tool/clipboard/web/. The curl and API are enabled in our server. It appears that the API request is not accepted by ‘pastebin.com’. Please contact the hosting provider for ‘pastebin.com’ and check regarding this issue.

I am contacting pastebin.com to get their support. Is there anything else to figure out where exactly or how exactly to fix this? either on my hosting or on pastebin.com

Thank you very much.

Ohh, Christ, where do these companies find these people :roll_eyes:

No, that has nothing to do with cURL or the API or Pastebin. The host name does not resolve and there is nothing Pastebin can do about that. There is some issue with your host’s DNS resolver and only they can tell whats wrong and potentially fix it.

:sleeping::sleeping::sleeping:

I will check with my hosting again. thank you :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.