我试图实现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);
}
}
2条答案
按热度按时间1wnzp6jl1#
建议您使用Dio库来更方便地处理HTTP请求https://pub.dev/packages/dio
vddsk6oq2#
https://pub.dev/packages/http_interceptor/versions/2.0.0-beta.6中提供了对拦截MultiPartForm数据的支持。