Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is my code snippet
- HttpParams httpParams = new BasicHttpParams();
- HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
- // set request params
- httpParams.setParameter("http.language.Accept-Language", "en-us");
- httpParams.setParameter("http.protocol.content-charset", "UTF-8");
- httpParams.setParameter("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
- httpParams.setParameter("http.connection.stalecheck", false); // turn off stale check checking for performance reasons
- SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
- schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
- final ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
- httpClient = new DefaultHttpClient(cm, httpParams);
- HttpConnectionParams.setConnectionTimeout(httpParams, 1000);
- HttpConnectionParams.setSoTimeout(httpParams, 10000);
- httpClient.getParams().setParameter("http.connection.timeout", 1000);
- httpClient.getParams().setParameter("http.tcp.nodelay", true);
- and this is my log
- 2012-01-04 11:12:05 HtmlFetch [DEBUG] Initializing HttpClient
- 2012-01-04 11:12:05 SingleClientConnManager [DEBUG] Get connection for route HttpRoute[{}->http://192.168.2.59]
- 2012-01-04 11:12:05 DefaultClientConnectionOperator [DEBUG] Connecting to 192.168.2.59:80
- 2012-01-04 11:12:05 RequestAddCookies [DEBUG] CookieSpec selected: best-match
- 2012-01-04 11:12:05 RequestAuthCache [DEBUG] Auth cache not set in the context
- 2012-01-04 11:12:05 DefaultHttpClient [DEBUG] Attempt 1 to execute request
- 2012-01-04 11:12:05 DefaultClientConnection [DEBUG] Sending request: GET /test.php HTTP/1.1
- 2012-01-04 11:12:05 wire [DEBUG] >> "GET /test.php HTTP/1.1[\r][\n]"
- 2012-01-04 11:12:05 wire [DEBUG] >> "Host: 192.168.2.59[\r][\n]"
- 2012-01-04 11:12:05 wire [DEBUG] >> "Connection: Keep-Alive[\r][\n]"
- 2012-01-04 11:12:05 wire [DEBUG] >> "User-Agent: Apache-HttpClient/4.1.2 (java 1.5)[\r][\n]"
- 2012-01-04 11:12:05 wire [DEBUG] >> "[\r][\n]"
- 2012-01-04 11:12:05 headers [DEBUG] >> GET /test.php HTTP/1.1
- 2012-01-04 11:12:05 headers [DEBUG] >> Host: 192.168.2.59
- 2012-01-04 11:12:05 headers [DEBUG] >> Connection: Keep-Alive
- 2012-01-04 11:12:05 headers [DEBUG] >> User-Agent: Apache-HttpClient/4.1.2 (java 1.5)
- 2012-01-04 11:12:15 wire [DEBUG] << "HTTP/1.1 200 OK[\r][\n]"
- 2012-01-04 11:12:15 wire [DEBUG] << "Date: Wed, 04 Jan 2012 05:42:05 GMT[\r][\n]"
- 2012-01-04 11:12:15 wire [DEBUG] << "Server: Apache/2.2.17 (Ubuntu)[\r][\n]"
- 2012-01-04 11:12:15 wire [DEBUG] << "X-Powered-By: PHP/5.3.5-1ubuntu7.4[\r][\n]"
- 2012-01-04 11:12:15 wire [DEBUG] << "Vary: Accept-Encoding[\r][\n]"
- 2012-01-04 11:12:15 wire [DEBUG] << "Content-Length: 0[\r][\n]"
- 2012-01-04 11:12:15 wire [DEBUG] << "Keep-Alive: timeout=15, max=100[\r][\n]"
- 2012-01-04 11:12:15 wire [DEBUG] << "Connection: Keep-Alive[\r][\n]"
- 2012-01-04 11:12:15 wire [DEBUG] << "Content-Type: text/html[\r][\n]"
- 2012-01-04 11:12:15 wire [DEBUG] << "[\r][\n]"
- 2012-01-04 11:12:15 DefaultClientConnection [DEBUG] Receiving response: HTTP/1.1 200 OK
- 2012-01-04 11:12:15 headers [DEBUG] << HTTP/1.1 200 OK
- 2012-01-04 11:12:15 headers [DEBUG] << Date: Wed, 04 Jan 2012 05:42:05 GMT
- 2012-01-04 11:12:15 headers [DEBUG] << Server: Apache/2.2.17 (Ubuntu)
- 2012-01-04 11:12:15 headers [DEBUG] << X-Powered-By: PHP/5.3.5-1ubuntu7.4
- 2012-01-04 11:12:15 headers [DEBUG] << Vary: Accept-Encoding
- 2012-01-04 11:12:15 headers [DEBUG] << Content-Length: 0
- 2012-01-04 11:12:15 headers [DEBUG] << Keep-Alive: timeout=15, max=100
- 2012-01-04 11:12:15 headers [DEBUG] << Connection: Keep-Alive
- 2012-01-04 11:12:15 headers [DEBUG] << Content-Type: text/html
- 2012-01-04 11:12:15 ThreadSafeClientConnManager [DEBUG] Shutting down
- 2012-01-04 11:12:15 DefaultHttpClient [DEBUG] Connection can be kept alive for 15000 MILLISECONDS
- 2012-01-04 11:12:15 SingleClientConnManager [DEBUG] Releasing connection org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@147c1db
- Here DefaultHttpClient [DEBUG] Connection can be kept alive for 15000 MILLISECONDS . Is this default time out ???
Advertisement
Add Comment
Please, Sign In to add comment