繁体   English   中英

CURL 状态返回内部服务器错误500

[英]CURL status returns internal server error 500

我正在尝试从 apirone 实施比特币网关。 问题是,当我运行 CURL function 时,它返回内部服务器错误 500。

所以我试着运行他们的演示代码。 虽然它在他们的网站上运行良好,但它返回相同的内部服务器错误 ii 在我的服务器上尝试。 下面是代码

<?php
  $json_data = array (
    'type' => "forwarding",
    'currency' => "btc",
    'callback' => array(
        'url'=> "http://example.com/callback",
        'data' => array (
            'invoice_id' => "1234"
        )
    ),
    'destinations' => array (        
        array('address' => "1apiKcJM95jENZeom2dQo8ShK7dUQkRaS", 'amount' => 40330),
        array('address' => "1ApiwpetcWnBbkpU7cb7biPfc6Tiucasf8", 'amount' => 40330)
    )
  );
  
  $api_endpoint = "https://apirone.com/api/v2/wallet";
 
  $curl = curl_init($api_endpoint);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($json_data));
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  $response = curl_exec($curl);
  $http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  curl_close($curl);
 
  if ($http_status_code==200){
      $decoded = json_decode($response, true);
      echo "Wallet: " . $decoded["wallet"] . "<BR>";
      echo "Key: " . $decoded["transfer_key"];
  } else {
      var_dump($response);
  }
?>

更多细节可以在这里找到https://apirone.com/docs/forwarding-wallet

有人可以让我知道可能导致此错误的原因吗?

谢谢

我认为这可能是 cURL 设置问题。

尝试放置

curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));

之后

curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($json_data));

另外,我不会直接在 function 参数中使用json_encode($json_data) 尝试对其进行编码,然后在CURLOPT_POSTFIELDS选项中发送已编码的 json。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM