首页 > 解决方案 > 为什么我的有效载荷没有随这个 POST 请求一起发送?

问题描述

我正在尝试使用有效负载($data)向我的 API 发送 POST 请求。

  $api = new CoindRPC();
  $txninfo = $api->gettransaction($argv[1]);
  $txinforaw = $api->getrawtransaction($txninfo['txid']);
  error_log('=== WALLETNOTIFY ===');
  error_log('txninfo: '. print_r($txninfo,true));
  $page_containing_sender = file_get_contents('http://redacted.com/api/getrawtransaction?txid=' . $txninfo['txid'] . '&decrypt=1');
  $sender_parent_obj = json_decode($page_containing_sender, true);
  $possible_senders = $sender_parent_obj['vout'][0]['scriptPubKey']['addresses'];
  $encoded_possible_senders = json_encode($possible_senders);
  echo json_encode($possible_senders);
  $url = 'https://redacted.com/api/register_domain_name';
  foreach($txninfo['details'] as $id => $details) {
     $data = array(
        'txid'     => $txninfo['txid'],
        'tot_amt'  => $txninfo['amount'],
        'tot_fee'  => $txninfo['fee'],
        'confirmations'=> $txninfo['confirmations'],
        'comment'  => $txninfo['comment'],
        'blocktime'=> $txninfo['blocktime'] ? $txninfo['blocktime']:$txninfo['time'],
        'account'  => $details['account'],
        'address'  => $details['address'],
        'category' => $details['category'],
        'amount'   => $details['amount'],
        'fee'      => $details['fee'],
        'possible_senders' => $encoded_possible_senders,
     );
  }
  $options = array(
     'http' => array(
        'header'=> array(
           'WWW-Authenticate: Token',
           'Authorization: Token [redacted]',
           'Accept: application/json',
           'Content-type: application/json'
        ),
        'method'=> 'POST',
        'content'=> json_encode($data),
     ),
  );
  $context = stream_context_create($options);
  $result = file_get_contents($url, false, $context);

在我的 API 中,我得到了 500,因为每当我尝试检索 POST 数据时,我发现没有。有谁知道出了什么问题?我真的很感激一些帮助。提前感谢您的任何帮助。

我尝试过:将 json_encode 更改为 http_build_query,将 Accept 更改为 http_build_query 的适当类型,并将 Content-type 更改为 http_build_query 的适当类型。

标签: php

解决方案


推荐阅读