时间:2021-07-01 10:21:17 帮助过:24人阅读
curl -H "Content-type: application/json" -X POST -d '{ "aaa": "aaa" "bb": "bb", "cc": { "cc1": "cc1", "cc2": "cc3" } }' "http://xxx"
$fields = array( "aa" => "aa", "bb" => "bb");$response = http_post_fields("http://xxx", $fields);echo $response;
$fields = json_encode($fields);
谢谢,还是不成功,
打印echo $response; 不出任何东西
如何把以下代码
curl -H "Content-type: application/json" -X POST -d '{ "aaa": "aaa" "bb": "bb", "cc": { "cc1": "cc1", "cc2": "cc3" } }' "http://xxx"
$fields = array( "aa" => "aa", "bb" => "bb");$response = http_post_fields("http://xxx", $fields);echo $response;
你那 -d 不是 这样的串吗?'{
"aaa": "aaa"
"bb": "bb",
"cc": {
"cc1": "cc1",
"cc2": "cc3"
}
}'
是这样的串,jason后的结果是相同的,然而还是不成功。
但是curl就成功了
所以我试图打印echo $response;,但是没什么结果,如何跟踪post请求啊?好定位错误?
你那 -d 不是 这样的串吗?'{
"aaa": "aaa"
"bb": "bb",
"cc": {
"cc1": "cc1",
"cc2": "cc3"
}
}'
json_encode($value);
用curl啊
PHP 测试 "aa", "bb" => "bb");$fieldsdate = json_encode($fields);$ch = curl_init("http://xxx");curl_setopt($ch, CURLOPT_HEADER, "Content-type: application/json");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsdate);$output = curl_exec($ch);if(curl_errno($ch)){//出错则显示错误信息 print curl_error($ch);}curl_close($ch);echo $output;?>