2012-09-28 76 views
0

我將HttpParameters設置爲HttpClient。Android:如何將ConnectionTimeOut值設置爲HttpClient

現在我想測試它們是否設置正確。其實我做這種方式:

public class MyHttpClient extends DefaultHttpClient { 

    public MyHttpClient(int tc, int ts) { 

     HttpParams httpParameters = new BasicHttpParams(); 
     // Set the timeout in milliseconds until a connection is established. 
     int timeoutConnection = tc; 
     HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); 
     // Set the default socket timeout (SO_TIMEOUT) 
     // in milliseconds which is the timeout for waiting for data. 
     int timeoutSocket = ts; 
     HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); 
     ClientConnectionManager mgr = this.getConnectionManager(); 
     this.setParams(httpParameters); 
    } 
} 

像這樣創建它的一個實例:

public static MyHttpClient httpclient = new MyHttpClient(5000, 5000); 

如何知道這是否實際工作。 。

我嘗試這樣做:

httpclient.getParams()的toString();

和我得到這個作爲輸出:

[email protected] 

好像其Default Params但不是我設置。

回答

1

使用這些代碼行

HttpParams httpParameters = new BasicHttpParams(); 
    int timeoutConnection = 120000; 
      HttpConnectionParams.getConnectionTimeout(httpParameters)); 
+0

我已經把params。我只想獲得我設定的值。就像「httpclient.getParams()。getConnectionTimeout」。 –

+0

我編輯我的答案試試這個 –

1

我使用:

HttpParams params = new BasicHttpParams(); 
params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); 
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); 
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, CONNECTION_TIMEOUT); 
params.setLongParameter(ConnManagerPNames.TIMEOUT, CONNECTION_TIMEOUT); 
HttpClient httpClient = new DefaultHttpClient(params); 
+0

我已經設置了參數。我只想獲得我設定的值。就像「httpclient.getParams()。getConnectionTimeout」。 –

+0

嘗試httpClient.getParams()。getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,CONNECTION_TIMEOUT); – Casabian

相關問題