0
我正在嘗試使用curl發送JSON數據,但它沒有發佈。如何使用curl發佈JSON數據?
$data = array("name" => " Hagrid", "age" => "36");
$content= json_encode($data,true);
$url ='http://www.example.com/webervices/msg.php';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
print_r($status);
curl_close($curl);
$response = json_decode($json_response, true);
而且在msg.php
print_r($_POST);
但它打印空白陣列。
如果有人有任何使用php發佈JSON數據的解決方案,這將是有幫助的。
你看着辦吧如何做到這一點了嗎?我來到現在像你一樣的問題= http://stackoverflow.com/questions/28309035/post-json-data-using-curl-php。我想知道是否可以回答 - 如果你知道答案。謝謝隊友:) – 2015-02-03 21:26:08