flutter 如何在多部分请求中使用http包了解http_interceptor

0g0grzrc  于 2023-06-24  发布在  Flutter
关注(0)|答案(2)|浏览(106)

我试图实现http_interceptor刷新访问令牌到期和重试http请求....我已经在互联网上搜索,但我没有找到任何有用的链接工作以下是我的代码,多部分请求,我想实现http_interceptor

Future<void> postImage(BuildContext context, String imageType) async {
    var data = {"imagetype": imageType, "filename": imageType};
    Map<String, String> obj = {"attributes": json.encode(data).toString()};
    var flutterFunctions =
        Provider.of<FlutterFunctions>(context, listen: false);
    final url = Ninecabsapi().urlHost + Ninecabsapi().getvehicle;
    try {
      loading();
      var response = await http.MultipartRequest("POST", Uri.parse(url))
        ..files.add(await http.MultipartFile.fromPath(
            "imagefile", flutterFunctions.imageFile!.path,
            contentType: MediaType("image", "jpg")))
        ..headers['Authorization'] = token!
        ..fields.addAll(obj);
      loading();
      notifyListeners();
    } catch (e) {
      print(e);
    }
  }

相关问题