【问题标题】:Curl working on local but not working on live domain卷曲在本地工作但不在实时域上工作
【发布时间】:2018-01-09 23:10:03
【问题描述】:
$url="http://182.191.78.79:92/api/ERP/Login?UserName=xxx&Password=xxx&LocationId=";

$secretKey = "sk_test_1234567";



  // append the header putting the secret key and hash

  $request_headers = array();
//  $request_headers[] = 'Authorization: Bearer ' . $secretKey;
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 60);
 // curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $data = curl_exec($ch);

  if (curl_errno($ch))
    {
    print "Error: " . curl_error($ch);
    }
    else
    {
    // Show me the result

    $transaction = json_decode($data, TRUE);

    curl_close($ch);

    var_dump($transaction);

  }

【问题讨论】:

  • 请格式化您的代码并提供详细说明。
  • 我最喜欢的故障排除问题:尝试时会发生什么?您是否收到任何错误消息?
  • 不工作怎么办?错误信息?结果错误?电脑会不会死机?请阅读:How to create a Minimal, Complete, and Verifiable exampleHow do I ask a good question?
  • 开启报错并执行脚本。然后,如果有任何异常,您可能会看到 PHP 错误。有时这可能是由您的防火墙引起的问题。
  • 错误:无法连接到 182.191.78.79 端口 92:连接被拒绝

标签: php codeigniter


【解决方案1】:

您是否检查过 curl 在您的服务器上的 PHP 中是否可用?

function _isCurl(){
    return function_exists('curl_version');
}

来源:https://stackoverflow.com/a/13433965/4934937

如果你的服务器运行的是 php5 并且使用的是 linux,你可以尝试安装 php5-curl 包,因为它默认没有安装。

【讨论】:

  • 这个函数返回1
  • 这是什么意思相同的代码在本地 Apache 服务器上运行但在实时域上运行。
  • 根据您的评论“连接被拒绝” - 这似乎是与白名单相关的错误,因此您可以将实时服务器的 IP 地址列入白名单。
猜你喜欢
  • 2022-11-09
  • 1970-01-01
  • 1970-01-01
  • 2012-10-31
  • 2014-01-02
  • 1970-01-01
  • 2019-10-01
  • 2016-03-05
  • 1970-01-01
相关资源
最近更新 更多