package com.google.code.http4j.example;
import java.io.IOException;
import java.net.URISyntaxException;
import com.google.code.http4j.Client;
import com.google.code.http4j.Response;
import com.google.code.http4j.impl.BasicClient;
import com.google.code.http4j.utils.Metrics;
public class BasicExample {
public static void main(String[] args) throws Exception {
Client client = new BasicClient();
Response response = client.get("http://code.google.com/p/http4j/");
Metrics metrics = response.getMetrics();
System.out.println("Bytes sent:" + metrics.getBytesSent());
System.out.println("Bytes received:" + metrics.getBytesReceived());
System.out.println("Blocking cost:" + metrics.getBlockingCost());
System.out.println("DNS lookup cost:" + metrics.getDnsLookupCost());
System.out.println("Connection establish cost:" + metrics.getConnectingCost());
System.out.println("Sending cost:" + metrics.getSendingCost());
System.out.println("Waiting cost:" + metrics.getWaitingCost());
System.out.println("Receiving cost:" + metrics.getReceivingCost());
System.out.println("SSL handshake cost:" + metrics.getSslHandshakeCost());
response.output(System.out);
client.shutdown();
}
}
Java 的 HTTP 客户端 http4j 示例代码
最新推荐文章于 2021-02-12 16:37:02 发布
本文通过一个示例展示了如何使用HTTP4J库来获取HTTP请求的详细性能指标,包括发送和接收的字节数、阻塞成本、DNS查找成本等。
2031

被折叠的 条评论
为什么被折叠?



