簡體   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