hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: make connection alive
Date Thu, 07 Oct 2010 12:06:52 GMT
On Thu, 2010-10-07 at 17:31 +0900, Andrey V. Panov wrote:
> Hi all.
> I want use single connection (for auth case) for all my requests.
> By default it's should keep connection alive but after my POST request it's
> close it! (cheking with nestat).
> 
> HttpClient v4.0.3. Server is IIS (not sure about version)
> 
> I need make auth to server via POSTing and keep connection for future use...
> Correct me please if you see something wrong in my example:
> 
> EXAMPLE:
>         DefaultHttpClient client = new DefaultHttpClient();
> 
>         HttpGet get = new HttpGet(Helper.indexUrl);
>         HttpResponse response = client.execute(get);
> 
>         HttpEntity entity = response.getEntity();
>         System.out.println(EntityUtils.toString(entity));
>         Thread.sleep(5000);
> 
> //Connection still opened here
> 
>         ArrayList<NameValuePair> formparams = new
> ArrayList<NameValuePair>();
>         formparams.add(new BasicNameValuePair("username", "bitova"));
>         formparams.add(new BasicNameValuePair("userpassword", "*****"));
>         formparams.add(new BasicNameValuePair("B1", "enter"));
>         UrlEncodedFormEntity entity2 = new UrlEncodedFormEntity(formparams,
> "windows-1251");
> 
>         HttpPost post = new HttpPost(Helper.indexUrl + Helper.authUrl);
>         post.setEntity(entity2);
> 
>         HttpResponse response1 = client.execute(post);
>         System.out.println(EntityUtils.toString(response1.getEntity()));
> 
> //Connection already closed!
>         System.out.println("check netstat");
>         Thread.sleep(15000);

Not all connections can be kept alive for various reasons. Use wire /
context logging to find out why the connection was dropped. 

http://hc.apache.org/httpcomponents-client-ga/logging.html

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message