如何在flutter中发布带有身份验证标识符和秘密的api

问题描述 投票:0回答:1

我想通过post方法在flutter中使用标识符和秘密来获取数据 我应该在 post 方法中哪里添加“标识符”和“秘密”? 在邮递员中,他们添加到正文中并且有效,但我无法将这些添加到颤振代码中:

未来的帖子(字符串 url,var 数据)异步 {

字符串 url = 'https://member.example.com/includes/api.php';

var 数据 = {

'identifier': 'identifier code otm7LE8OzlBmprXn',

'secret': 'secret code SXZgmDpX8miT31PSRQ',

'action': 'GetInvoices',

'userid': 6414,

'orderby': 'date',

'responstype': 'json',

};

尝试{

final response = await http.post(

  Uri.parse(url),
  headers: <String, String>{
    'Content-Type': 'application/json; charset=UTF-8',
    'Accept': 'application/json',
  },
  body: jsonEncode(data),
);

} 抓住 (e) {

print(e);

} }

E/flutter(6118):结果=错误;消息=身份验证失败

flutter async-await stateless
1个回答
0
投票

从正文中删除 jsonEncode:jsonEncode(data)。

body:数据对我有用

© www.soinside.com 2019 - 2024. All rights reserved.