本文介绍了cURL给出无法解析主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的新的专用服务器,我curl连接上gettin错误。
I am on my new dedicated server and i am gettin error on curl connections.
我尝试了一个
$_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, 'http://api.beatport.com/catalog/labels/detail?id=14248&format=json&v=1.0' );
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));
我得到
bool(false) array(21) { ["url"]=> string(72) "http://api.beatport.com/catalog/labels/detail?id=14248&format=json&v=1.0" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["certinfo"]=> array(0) { } } string(40) "Couldn't resolve host 'api.beatport.com'"
$ b b
可能是DNS问题?
that may be a DNS issue ?
已解决:
添加了我想通过curl检索的网站的ip和它工作!
i opened /etc/hosts and added the ip of the website that i want to retrieve via curl and it worked !
推荐答案
这实际上是专用服务器上的DNS配置问题。检查您的托管服务是否允许传出curl连接。
Your code is OK. This is actually an DNS configuration problem on the dedicated server. Check that your hosting service permits outgoing curl connexions.
这篇关于cURL给出无法解析主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!