我可以连接rest api,但是我希望将rest api与我自己的值连接起来。这是我的代码:
var formContent = {
"grant_type": "1",
"branchcode": "1",
"password": "1",
"username": "1",
"dbname": "1",
"dbuser": "1",
"dbpassword": "1",
"dbtype": "1"
};
Future<String> getData() async {
http.Response response = await http.get(
Uri.encodeFull("http://localhost:7070/api/v2/token"),
headers: {"Accept": "application/json"});
print(response.body);
}
怎么能在我的getData()函数上使用我的formContent?我想将http://localhost:7070/api/v2/token与我的表单内容联系起来,我将获得令牌。
要使用http请求发布数据,您必须使用post命令
var postBody= json.encode(formContent);
var resopnse = await http.post(
Uri.encodeFull("http://localhost:7070/api/v2/token"),
body: postBody,
headers: {"Accept": "application/json"});
要导入json编码器,请导入dart:convert包
import 'dart:convert';