Send API From Nodejs (express js) Project to Flutter Project

huangapple go评论67阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月26日 15:53:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554616.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定