我正在使用“ 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'},
添加回答
举报
0/150
提交
取消