当前位置: 首页 > 工具软件 > http4j > 使用案例 >

Java 的 HTTP 客户端 http4j 示例代码

傅振濂
2023-12-01
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();
}
}
 类似资料: