我刚接触过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
发布于 2013-06-07 20:27:52
我运行了以下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(输入::all()),并得到以下输出
{"name":"John","surname":"Doe"}HomeController.php
public function test()
{
return json_encode(Input::all());
}routes.php
Route::post('/test', 'HomeController@test');https://stackoverflow.com/questions/16586586
复制相似问题