0

我将 HttpParameters 设置为 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();

我得到了这个作为输出:

org.apache.http.params.BasicHttpParams@40520f20

似乎是我设置的Default Params但不是我设置的。

4

2 回答 2

1

使用这些代码行

HttpParams httpParameters = new BasicHttpParams();
    int timeoutConnection = 120000;
            HttpConnectionParams.getConnectionTimeout(httpParameters));
于 2012-09-28T07:33:45.003 回答
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);
于 2012-09-28T07:34:13.087 回答