我们使用 OkHttp 库进行 API 调用 (http://square.github.io/okhttp/(。
我们正在寻找一种使用 Java 来测量以下响应时间(链接到 http 协议(的解决方案:
- 域名解析查找
- TCP连接
- 内容生成
- 内容传输
到目前为止,我们还没有找到如何使用Java来做到这一点。有什么想法吗?
对于 Http 日志。使用 HttpLoggingInterceptor 查看响应时间和日志。
拦截器的格拉德尔:
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
用于在 OkHTTP 中登录的代码
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
// set your desired log level
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient httpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.connectionPool(new ConnectionPool(20, 60, TimeUnit.SECONDS))
.retryOnConnectionFailure(true)
.addInterceptor(logging)
.build();
我想你只在寻找这个
查看更多日志记录信息:
阅读维基:https://github.com/square/okhttp/wiki/Interceptors
https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor