【发布时间】:2020-07-23 14:21:33
【问题描述】:
我有一个 API,它是用 Node.js 编写的。它用于记录目的。现在我正在使用来自颤振应用程序的相同 API 来执行相同的操作。
API : http://192.168.137.1:5050/User/Login
如何从 Flutter 应用向 API 发布数据
Expected Input :
{ Data: { USER_NAME: 'usenmae', PASSWORD: 'password' } }
1.来自 Flutter
static Future<String> loginPost(String email, String password) async {
Map<String, dynamic> jsonMap = {
'Data': {'USER_NAME': email,'PASSWORD' : password}
};
try {
final response = await http.post(
'http://192.168.137.1:5050/User/Login',
body: jsonMap,
);
return response.body;
} catch (exception) {
}
return null;
}
使用上面的代码 sn-ps 调用 API 后出现一些错误
Error : I/flutter ( 4149): send message exception called
I/flutter ( 4149): type '_InternalLinkedHashMap<String, String>' is not a subtype of type 'String' in type cast
我想通过 api 传递用户名和密码,方法是用另一个 Data 对象包装它们,看起来像 { Data: { USER_NAME: 'usenmae', PASSWORD: 'password' } }
谢谢
【问题讨论】:
标签: flutter