简体   繁体   中英

HttpComponents freezes when calling HttpResponse response2 = conn.receiveResponseHeader();

I'm trying some basic stuff with HttpComponents .

I'm getting a strange issue with conn.receiveResponseHeader(); . Perhaps I'm not using it properly, but I cannot see what it is.

When the program reaches this line, it simple pauses indefinitely. When I debug, and evaluate that expression it says "(pending)" forever.

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();

    }

}

Do not forget to flush internal session buffer

 conn.bind(socket);
 conn.sendRequestHeader(request2);
 conn.flush();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM