【问题标题】:Curl return false on hostinger server (curl enabled)Curl 在托管服务器上返回 false(启用 curl)
【发布时间】:2016-04-28 00:51:45
【问题描述】:

使用:

主机免费
php 5.5.26
卷曲已启用 7.19.7
“laravel/framework”:“5.2.*”和“vladkens/vk”:“^0.1.9”

我使用这个函数得到了错误的响应(bool(false)):

private function request($url, $method = 'GET', $postfields = array())
{
    curl_setopt_array($this->ch, array(
        CURLOPT_USERAGENT =>"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_POST => ($method == 'POST'),
        CURLOPT_POSTFIELDS => $postfields,
        CURLOPT_URL => $url
    ));

    return curl_exec($this->ch);
}

使用curl_getinfo($this->ch) 获取此调试数据:

array(23) { ["url"]=> string(251) "https://api.vk.com/method/audio.search.json?access_token={{access_token}}&api_id={{api_id}}&q=21+Hunter+Hayes&random=1014×tamp=1453393550&v=2.0&sig={{sig}}" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(0) ["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) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(0) "" ["certinfo"]=> array(0) { } } 

如果我直接在浏览器中使用这个数组url 值,我将得到正确的 api.vk.com 数据响应。

我错过了什么?
更新:
使用echo $error = curl_error($this->ch); 获取此消息couldn't connect to host

【问题讨论】:

    标签: php curl laravel-5 vk vk-sdk


    【解决方案1】:

    您似乎无法从您的服务器访问互联网。 听起来像是防火墙问题。 转到您的面板并确保没有防火墙规则阻止您访问外部网站。由于您的托管计划,这可能是一个限制。

    【讨论】:

    • 是的,你是对的。我联系了 IT 支持并hostinger 阻止您访问具有免费计划的 php curl 功能的外部网站。
    猜你喜欢
    • 1970-01-01
    • 2011-08-05
    • 2017-10-24
    • 2012-07-19
    • 2013-07-03
    • 2014-02-18
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多