为什么Chrome在使用“ fetch()”时发送空的正文,但Edge正确发送了正文

我正在使用“ fetch()”方法向另一个服务器发送请求,但使用Chrome发送的请求的正文为空。


发送请求的应用程序是Vue应用程序,服务器正在使用AdonisJS。我已经在Microsoft Edge中尝试了我的应用程序,但主体不是空的。


Vue中的请求:


const requestOptions = {

    method: 'POST',

    headers: {'Content-Type': 'application/plain'},

    body: JSON.stringify({username, password}),

};

let req = fetch('http://localhost:3333/user/login', requestOptions)

    .then(response => {

        return response.text();

    }).then(json => {

        this.$refs.debug.innerHTML = json

    })


AdonisJS中的控制器:


async login({request, response}) {

    console.log("params", request.raw());

    return '{"key": "value"}';

}


www说
浏览 164回答 1
1回答

回首忆惘然

改变    headers: {'Content-Type': 'application/plain'},至    headers: {'Content-Type': 'application/json'},
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript