【发布时间】:2019-09-10 22:07:00
【问题描述】:
我遇到了一个问题,我在 Vue 应用程序中使用 fetch 来调用我的 Laravel API。 但是,我在 Laravel 中的请求对象是空的
这是在 laravel 6 中使用 fetch。我尝试使用 postman 和 axios 都可以正常工作。
const requestOptions = {
method: 'POST',
headers: requestHeader(false),
/* eslint-disable-next-line */
body: JSON.stringify({ "email": 'test@test.com', "password": 'password' })
}
return fetch(`${baseUrl}/auth/authenticate`, requestOptions)
Laravel 控制器:
public function authenticate(Request $request) : JsonResponse
{
return response()->json(['message' => $request], 422);
}
$request 对象为空。
如果我这样做。然后我看到了数据:
$data = json_decode($request->getContent(), true);
不确定我在获取时做错了什么。任何帮助将不胜感激
【问题讨论】: