【问题标题】:Code that works fine on local but not on server在本地运行良好但在服务器上运行良好的代码
【发布时间】:2017-06-16 16:53:57
【问题描述】:

所以我的代码的目的是从 curl 获得响应。

这里有一个参考方法

public function waybill($waybill, $courier)
{
    $curl = curl_init();

    curl_setopt_array($curl, array(
        [Some CURLOPT here..]
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
        return "cURL Error #:" . $err;
    } else {
        return $response;
    }
}

然后我从这里调用方法

public function getWaybill($carrier, $tracking_number)
{
    $waybill = $tracking_number;
    $courier = strtolower($carrier);

    $response = $this->helper->waybill($waybill, $courier);
    $response = json_decode($response, true);
    $response = $response['rajaongkir']['result'];
    $response = $response['summary']['status'];
    if (!empty($response)) {
        return $response;
    } else {
        return "Invalid tracking data";
    }
}

如果响应为空,则在本地显示“无效的跟踪数据”,但在服务器中不显示任何内容。

【问题讨论】:

  • 开启报错看看是什么原因
  • 出于调试目的使用error_reporting(E_ALL);。也许您的服务器上的 curl 扩展程序已关闭?
  • 您是否尝试卷曲 https 网址?您是否正确安装了证书?

标签: php curl server


【解决方案1】:

尝试创建一个仅包含此内容的页面

<?php
    if (in_array ('curl', get_loaded_extensions())) {
    echo true;
}
else {
    echo false;
}

这会让你知道 curl 是否启用(if get_loaded_extensions() 未被禁用)......可能是你的问题.. 不然老了

<?php phpinfo();

并且搜索 curl 也可以(如果您的服务器上允许使用 phpinfo)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    • 2013-06-08
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多