Laravel不接受JSON请求。如果我以表单数据的形式请求,它可以工作,但是如果我在postman中发布JSON对象,那么它就不会接收请求数据。
路由:
$router->group(['prefix' => 'imp'], function () use ($router) {
$router->group(['prefix' => 'lead'], function () use ($router) {
$router->post('/jardy', 'FeedController@jardy');
});
});主计长:
public function jardy(Request $request)
{
$this->validate($request, [
'api_key' => 'required',
]);
$api_key = $request->input('api_key');
return $api_key;
}JSON请求:

表格资料要求:

为什么不适用于JSON,content-type是application/json,Accept:*/*?
发布于 2020-09-23 13:46:25
JSON中不允许注释。字段主体-> raw -> json中有一个bug
发布于 2020-09-02 15:04:07
您必须添加标题
接受:申请/json
然后laravel将您的原始json解析为输入var,它们可以使用->input()访问。
见:

使用/这是邮递员的默认设置,将无法工作。如果你不想在头上中继,你也可以做$request->json(),但我想,你只是想传递标题。
请参阅处理此问题的源代码:https://github.com/laravel/framework/blob/7.x/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php#L52
发布于 2022-09-22 13:17:02
在我的例子中,它缺少Content-Length头。
值应该是请求体的多个字符。
Content-Type: application/json也应该存在。
https://stackoverflow.com/questions/63706546
复制相似问题