0
我正在嘗試一些基本的東西HttpComponents
。HttpComponents在調用HttpResponse時凍結response2 = conn.receiveResponseHeader();
我收到一個奇怪的問題conn.receiveResponseHeader();
。也許我沒有正確使用它,但我看不到它是什麼。
當程序到達這一行時,它會無限期地暫停。當我調試,並評估表達它永遠說「(待定)」。
public class Test2 {
public static void main(String[] args) throws IOException, HttpException {
Socket socket = new Socket("www.booya.com", 80);
DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);
HttpRequest request2 = new BasicHttpRequest("GET", "/");
conn.bind(socket);
conn.sendRequestHeader(request2);
HttpResponse response2 = conn.receiveResponseHeader();
System.out.println(response2.getAllHeaders());
System.out.println(conn.isOpen());
HttpConnectionMetrics metrics = conn.getMetrics();
System.out.println(metrics.getRequestCount());
System.out.println(metrics.getResponseCount());
System.out.println(metrics.getReceivedBytesCount());
System.out.println(metrics.getSentBytesCount());
conn.close();
}
}