如何在Flutter中记录HTTP请求 [英] How to log http requests in flutter

查看:190
本文介绍了如何在Flutter中记录HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发带有Flutter的应用程序,并且在dart中使用默认的http包进行API调用。我们如何记录正在处理的所有http请求。

I am developing an app with flutter and I am using default http package in dart for making API calls. How do we log all the http requests which are going through. Is there any in built feature in http or middleware available for the same?

推荐答案

似乎没有内置的功能,以记录请求的方式。但是,您可以实现自己的客户端来记录请求:

There doesn't seem to be a built-in way to log request. However, you can implement your own Client to log request:

class MyClient extends BaseClient {
  MyClient(this.delegate);
  final Client delegate;
  Future<StreamedResponse> send(BaseRequest request) {
    _logRequest(request);
    return delegate.send(request);
  }
  void close() => delegate.close();
  void _logRequest(BaseRequest request) => ....;
}

这篇关于如何在Flutter中记录HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆