我是Laravel的新手,尝试使用以下cURL命令发布数据但是当我尝试读取数据时,它不会这样做。
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":100}' api.xyz.com/test
这里有一个解决方案*使用file_get_contents但我确信必须有更好的方法: Laravel - POST data is null when using external request
答案 0 :(得分:0)
我运行了以下curl命令
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name":"John", "surname":"Doe"}' http://localhost/laravel/public/test
并在我的HomeController @ test中返回了一个json_encode(Input :: all())并获得了以下输出
{"name":"John","surname":"Doe"}
<强> HomeController.php 强>
public function test()
{
return json_encode(Input::all());
}
<强> routes.php文件强>
Route::post('/test', 'HomeController@test');