React JS Fetch返回空响应但Postman不返回

CGr*_*fin 3 post promise laravel reactjs fetch-api

我有一个React JS应用程序试图登录基于令牌的API(我也在开发,使用Laravel 5.5和Laravel Passport).我正在尝试实现基本登录(使用用户名和密码登录,一旦验证就从服务器接收令牌,使用该令牌进行将来的查询).

我用来获取的代码如下:

function loginApi(username, password) {
    return fetch(loginUrl, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            grant_type: 'password',
            client_id: clientId,
            client_secret: clientSecret,
            username: username,
            password: password
        })

   }).then(handleApiErrors)
     .then(response => response.json)
}
Run Code Online (Sandbox Code Playgroud)

值得注意的是,它还没有完全完成,因为我目前只是想确定我要回复的反应.

我已经解决了遇到的正常问题,比如CORS问题,但是我现在遇到的问题是来自API的响应只是......空的.即使在Chrome的开发人员工具的"网络"标签中,如果我直接检查请求,则响应为空.

开发工具1

开发工具2

但是,如果我做了确切的相同与邮差查询,结果正是我所期望的.

邮差

这可能是什么问题?为什么完全相同的查询会返回不同的结果?

D. *_*lsh 7

.json是一个函数,需要调用.尝试..

.then(response => response.json())
Run Code Online (Sandbox Code Playgroud)

您当前正在返回.json解析函数.