在Flutter http请求中添加标头参数的通用方法

时间:2019-01-24 11:16:29

标签: dart flutter

我想将map作为标头参数传递。

 Future<HomeResponse> getHomeResponse(
      String url, Map<String, String> headers) async {
    http.Response response = await http.get(url,
        headers: {"token": headers["token"], "name": headers["name"]});
    final responseBody = json.decode(response.body);
    final statusCode = response.statusCode;
    if (statusCode != 200 || responseBody == null) {
      throw new ServerExceptionHandler(
          "An error ocurred : [Status Code : $statusCode]");
    }
    return new HomeResponse.fromJson(responseBody);
  }

0 个答案:

没有答案