首页 > 解决方案 > 如何将函数中的参数用于带有 Dio 包的 http 请求正文

问题描述

Future<void> login(String email, String password) async {
    String url = "https://phone-book-api.herokuapp.com/api/v1/signin";
    Response response;
    var dio = Dio();
    response = await dio.post(url,
        data: {"email": email, "password": password);
    print(response.data);
  }

如果我使用上面的代码创建函数,我会遇到一些错误,但是如果我用硬代码填充正文,则不会发生错误,并且我可以在代码示例下方收到响应

Future<void> login(String email, String password) async {
    String url = "https://phone-book-api.herokuapp.com/api/v1/signin";
    Response response;
    var dio = Dio();
    response = await dio.post(url,
        data: {"email": "l200140004@gmail.com", "password": "l200140004");
    print(response.data);
  }

任何人都可以帮助我并向我解释它的情况,请...

标签: flutterhttpdartmobiledio

解决方案


对不起大家,我的密码输入错误,所以可能是错误的


推荐阅读