2013-07-17 57 views
0

我該如何去獲取org.apache.commons.httpclient.methods.PostMethod或org.apache.commons.httpclient.HttpClient對象的基礎HttpConnection?Apache Commons HttpConnection:PostMethod - 獲取基礎HttpConnection

+0

爲什麼? HttpConnection是流讀取器的抽象,是否有任何方法可供您捕獲輸入/輸出流? –

+0

@BryanAbrams我試圖關閉從HttpConnection但不是PostMethod或HttpClient可能的陳舊連接。 – cxdf

回答

1

如果你有HttpClient一個實例可以使用此獲得HttpConnection參考:

PostMethod post = new PostMethod(url); 
    // ... 
    HttpClient httpclient = new HttpClient(); 
    httpclient.getHttpConnectionManager().getConnection(HostConfiguration.ANY_HOST_CONFIGURATION); 
    // ... 
    httpclient.executeMethod(post);