英文:
Send API From Nodejs (express js) Project to Flutter Project
问题
当我在Thunder Client中尝试时,参数可以正常发送,但当我切换到Flutter项目时,参数无法传递到Node.js API。
Flutter代码
var https = await http.post(
Uri.parse(
'https://api.birqr.click/check-user'),
body: {
'userId': '64708d926cf77c7ebb047199',
},
);
状态
400
{status: 'error', message: 'userId字段必填'}
我已将CORS插件添加到我的Node.js项目,但没有生效。
英文:
When I try in thunder client, the parameters are sent without any problem, but when I switch to the flutter project, the parameters do not go to the node js API.
Flutter code
var https = await http.post(
Uri.parse(
'https://api.birqr.click/check-user'),
body: {
'userId': '64708d926cf77c7ebb047199',
},
);
status
400
{status: 'error', message: 'userId field required'}
I added cors plugin to my node js project but it didn't work
答案1
得分: 1
来自Flutter的请求,使用http包的body部分发送,而不是request.query。您应该在您的Node.js项目中应用这个。
英文:
The request you send from flutter with http package's body comes as request.body, not as request.query. You should apply this in your node js project.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论