我有这样的方法,其中我试图用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($结果); –
试过了,不起作用。 –