我正在尝试使用Keep Alive重用HTTP连接 . 服务器支持Keep Alive,我发送Connection:Keep-Alive HTTP标头,并且在收到响应后,连接仍然是FIN(由Android客户端发起) . 一些帮助将不胜感激 .

这里有一些代码:

DefaultHttpClient client = new DefaultHttpClient(); 
client.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());
client.setReuseStrategy(new DefaultConnectionReuseStrategy());
HttpParams params = client.getParams();

ClientConnectionManager mgr = client.getConnectionManager();
client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);

HttpPost post = new HttpPost(URL);
post.setHeader("Connection","Keep-Alive");
ByteArrayEntity entity = new ByteArrayEntity(requestBundle.postString().getBytes());
entity.setContentType("application/xml");
post.setEntity(entity);
HttpResponse response = client.execute(post);

当我检查HTTP请求标头时,我看到了这些:

Connection: Keep-Alive\r\n
Content-Length: 459\r\n
Content-Type: application/xml\r\n
Host: xxx.yyy.com\r\n
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)\r\n

在HTTP响应头文件中,我看到:

HTTP/1.1 200 OK\r\n
Content-Type: application/xml\r\n
Content-Length: 8049\r\n
Date: Tue, 22 Jan 2013 03:14:40 GMT\r\n
Server: lighttpd/1.4.31\r\n

查看响应和其他TCP数据包通过线路,很明显Android客户端根据我不知道的某些HTTP客户端设置启动FIN,这些设置不是由服务器上的Keep-Alive设置引起的( HTTP响应不包含 Headers “Connection:close”) .

请赐教!

干杯,安德烈