为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

www说 2021-04-19 16:14:53
我正在使用“ 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"}';}
查看完整描述

1 回答

?
回首忆惘然

TA贡献1847条经验 获得超11个赞

改变

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

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


查看完整回答
反对 回复 2021-04-29
  • 1 回答
  • 0 关注
  • 163 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信