简体   繁体   English

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

[英]CURL status returns internal server error 500

Im trying to implement a bitcoin gateway from apirone.我正在尝试从 apirone 实施比特币网关。 The problem is that when i run the CURL function it returns an internal server error 500.问题是,当我运行 CURL function 时,它返回内部服务器错误 500。

so i tried to run their demo code.所以我试着运行他们的演示代码。 although it works fine on their site, it return the same internal server error ii try it on my server.虽然它在他们的网站上运行良好,但它返回相同的内部服务器错误 ii 在我的服务器上尝试。 Below is the code下面是代码

<?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);
  }
?>

more details can be found here https://apirone.com/docs/forwarding-wallet更多细节可以在这里找到https://apirone.com/docs/forwarding-wallet

can someone let me know what might be causing this error?有人可以让我知道可能导致此错误的原因吗?

Thanks谢谢

I think this might be a cURL settings issue.我认为这可能是 cURL 设置问题。

Try placing尝试放置

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

after the之后

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

Also, I wouldn't json_encode($json_data) directly in the function argument.另外,我不会直接在 function 参数中使用json_encode($json_data) Try encoding it before and send the already encoded json in the CURLOPT_POSTFIELDS option.尝试对其进行编码,然后在CURLOPT_POSTFIELDS选项中发送已编码的 json。

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

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