首页 > 解决方案 > “如何使用 Flutter 以最简单的方式调用带有登录凭据(如用户名和密码)的 post api”

问题描述

如何使用登录凭证(如用户名和密码)以最简单的方式使用 Flutter 调用 post api 请让我知道在 Flutter 中调用 post api 的数量。

标签: flutter

解决方案


通过使用以下方法,您可以在标题或正文中发送数据。

new http.Client()
.post(url, headers: {'Content-type': 'application/json','username':'****','password':'****'},
  body: JSON.encoder.convert({'username':'****','password':'****'}))
  .then((http.Response r) => r.body)
  .whenComplete(() => print('completed'));

推荐阅读