我有這樣的方法,其中我試圖用json
體發送POST
要求:捲曲後無法正常工作(不被髮送體)
public function executePost($url, $theBody, $headers){
$data_string = '{"apple": "fruit", "turnip": "vegetable"}'; // hard coded for now
\Log::info($data_string);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($headers, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
));
$result = curl_exec($ch);
\Log::info($result);
}
在接收端我沒有得到的數據我做:
\Log::info(\Input::all());
我什麼也沒有,即一個空的數組。我似乎無法弄清楚這有什麼問題。
它在使用WAMP的另一臺計算機上工作,我使用的是Ubuntu 16.04和PHP 5.6。
請向我們展示接收端代碼? –
嘗試使用$ _POST = json_decode(file_get_contents(「php:// input」),true)在接收端獲取數據;和print_r($ _ POST);它和var_dump($結果); –
試過了,不起作用。 –