首页 > 解决方案 > POST JSON CURL 命令到 PHP

问题描述

我在命令行中执行下面的查询并获得结果

curl -k --header "Authorization: Bearer fc68946e-6b31-45ba-9006-d3519a9e1464" -i -H "Content-Type: application/json" -X POST -d "{'reportName':'Aggregation/Archive Log','indexFrom':'1','reportParameter': {'QUERY_FROM_DATE':'NOW -30 MONTH','QUERY_TO_DATE':'NOW','SQLGuardHostName':'%','SHOW_ALIASES':'TRUE','REMOTE_SOURCE':'%'}}" https://10.10.9.239:8443/restAPI/online_report

我想用 php 执行这个命令。

你能帮我生成php代码吗?

<?php
$url = "https://10.10.9.239:8443/restAPI/online_report";
$data_json = "{'reportName':'Aggregation/Archive Log','indexFrom':'1','reportParameter': {'QUERY_FROM_DATE':'NOW -30 MONTH','QUERY_TO_DATE':'NOW','SQLGuardHostName':'%','SHOW_ALIASES':'TRUE','REMOTE_SOURCE':'%'}}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
?>

标签: phpjsoncurl

解决方案


推荐阅读