php - 为什么我的有效载荷没有随这个 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 的适当类型。
解决方案
推荐阅读
- android - 安装应用程序失败。确保您已设置 Android 开发环境:https://reactnative.dev/docs/environment-setup
- java - 需要使用 Java 8 替换 AWS lambda 中的所有逗号
- r - 来自 cv.glmnet 的警告消息
- r - 在R中找到两条线的交点
- javascript - 如何从 JavaScript 脚本在新选项卡中打开 url
- for-loop - 如何将最新的 100 个文件从数千个子文件夹复制到另一个文件夹?
- python - 有没有办法为两个不同的应用程序实际使用相同的端口号?
- azure - Azure Boards 无法添加用户
- python - 对用户在 Power BI 中输入的新数据样本从 Power BI 运行 Python 模型
- c# - C# Server 下载文件并同时传输给用户。下载失败 [Google 云端硬盘]