How to pass a variable inside a function?

前端 未结 1 1605
粉色の甜心
粉色の甜心 2021-01-29 12:05

I am using a API and passing a variable to the API\'s function but its working in this case: curl_init(\'https://www.coinpayments.net/api.php?txid=123456\');

I want to

相关标签:
1条回答
  • 2021-01-29 13:09

    when i fire above api url using browser it show error

    API requests can only be made via POST. For documentation see: https://www.coinpayments.net/apidoc
    

    so you have to pass variable as a post parameter using below code

    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://www.coinpayments.net/api.php",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "{'txn_id':".$txn_id."}",
      CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
        "content-type: application/json"
      ),
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
    ?>
    

    i got response from above url when i use above code

    {
       "error": "No HMAC signature sent",
       "result": []
    }
    
    0 讨论(0)
提交回复
热议问题