且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在flutter中使用表单数据进行http发布?

更新时间:2021-10-15 22:06:17

请改用Map,因为正文位于http包中仅具有3种类型:字符串,列表或映射。试试这个:

Use Map instead, because body in http package only has 3 types: String, List or Map. Try this:

final uri = 'https://na57.salesforce.com/services/oauth2/token';
var map = new Map<String, dynamic>();
map['grant_type'] = 'password';
map['client_id'] = '3MVG9dZJodJWITSviqdj3EnW.LrZ81MbuGBqgIxxxdD6u7Mru2NOEs8bHFoFyNw_nVKPhlF2EzDbNYI0rphQL';
map['client_secret'] = '42E131F37E4E05313646E1ED1D3788D76192EBECA7486D15BDDB8408B9726B42';
map['username'] = 'example@mail.com.us';
map['password'] = 'ABC1234563Af88jesKxPLVirJRW8wXvj3D';

http.Response response = await http.post(
    uri,
    body: map,
);