This seems to do the trick:

  httpClient.getParams().setParameter(
        ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2965);

working now.

/A

On 19 February 2010 18:20, Andreas Blomqvist <[email protected]>wrote:

> Since I am reusing my context between calls, im trying to have the same
> cookie store in the context like this:
>
>
>   context = new BasicHttpContext();
>         response = httpClient.execute(httpost, context);
>         CookieStore cookieStore = (CookieStore)
> httpClient.getCookieStore();
>        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
>
> But when I make another get request , the cookie changes. Log from call
>
> ---> First post with form:
>
>   [java] 2010-feb-19 17:15:33
> org.apache.http.client.protocol.RequestAddCookies process
>
>      [java] FIN: CookieSpec selected: best-match
>      [java] 2010-feb-19 17:15:33
> org.apache.http.client.protocol.RequestAddCookies process
>      [java] FIN: Cookie [version: 0][name: PHPSESSID][value: *
> ud60eqh6ihuje5veg03ct7ri44]*[domain: schema.sthlm.friskissvettis.se][path:
> /][expiry: null] match [schema.sthlm.friskissvettis.se:80/index.php]
>      [java] 2010-feb-19 17:15:33
> org.apache.http.impl.client.DefaultRequestDirector execute
>
>      [java] FIN: Attempt 1 to execute request
>
> --> new get request (redirect)
>
>      [java] 2010-feb-19 17:15:34
> org.apache.http.client.protocol.ResponseProcessCookies processCookies
>      [java] FIN: Cookie accepted: "[version: 0][name: PHPSESSID][value: *
> fltgeoj2joikbdlv4fe3un22t5*][domain: schema.sthlm.friskissvettis.se][path:
> /][expiry: null]".
>
> Why is the cookie not the same?
>
> Thx
> A
>
>
> On 19 February 2010 17:49, Andreas Blomqvist 
> <[email protected]>wrote:
>
>> Do I need to handle the Cookies manually? From the logs it looks like I'm
>> getting lots of different cookies. How do i set the cookie in the context ?
>>
>> Thx
>> A
>>
>>
>> On 19 February 2010 13:59, Andreas Blomqvist <[email protected]
>> > wrote:
>>
>>> "HttpClient handles all types of redirects automatically, except those
>>> explicitly prohibited by the HTTP specification as requiring user
>>> intervention" but isnt 302 such a code that doesnt allow redirect? Thats why
>>> I try to manually redirect in my code. But it doesnt seem to work.
>>>
>>> Thx
>>> A
>>>
>>>
>>> On 19 February 2010 12:05, Oleg Kalnichevski <[email protected]> wrote:
>>>
>>>> Andreas Blomqvist wrote:
>>>>
>>>>> I guess you mean this line:
>>>>>
>>>>>  [java] 2010-feb-19 10:46:34
>>>>> org.apache.commons.httpclient.HttpMethodDirector isRedirectNeeded
>>>>>
>>>>> I cant find that package anywhere in my libs. Very strange. But if we
>>>>> assume
>>>>> that it is 4.0 thats running (code wise) how do I set the redirect ?
>>>>>
>>>>> /A
>>>>>
>>>>>
>>>>
>>>> http://hc.apache.org/httpcomponents-client/tutorial/html/httpagent.html#d4e1199
>>>>
>>>>
>>>> Oleg
>>>>
>>>>
>>>>> On 19 February 2010 11:16, Oleg Kalnichevski <[email protected]> wrote:
>>>>>
>>>>>  Andreas Blomqvist wrote:
>>>>>>
>>>>>>  Hi
>>>>>>>
>>>>>>> I'm confused. Im using httpclient, httpcore and httpmime 4.0.1 jars.
>>>>>>> Is
>>>>>>> that
>>>>>>> not version 4 of HttpClient ?
>>>>>>>
>>>>>>> My code is trying to login in on a webpage by posting a form. But i'm
>>>>>>> not
>>>>>>> getting logged in until i make a second call with this code.
>>>>>>>
>>>>>>> What doesnt look right? the code or the logs (or both :) )
>>>>>>>
>>>>>>> Thx
>>>>>>>
>>>>>>> A
>>>>>>>
>>>>>>>
>>>>>>>  I am confused too, because I clearly see a log entry generated by
>>>>>> HttpClient 3.
>>>>>>
>>>>>> Oleg
>>>>>>
>>>>>>
>>>>>>
>>>>>>  On 19 February 2010 10:54, Oleg Kalnichevski <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>>  Andreas Blomqvist wrote:
>>>>>>>
>>>>>>>>  Thats for httpClient 3 ?
>>>>>>>>
>>>>>>>>> /A
>>>>>>>>>
>>>>>>>>> On 19 February 2010 08:56, Avlesh Singh <[email protected]> wrote:
>>>>>>>>>
>>>>>>>>>  It says redirect is disabled? How do enable it? I thought redirect
>>>>>>>>> was
>>>>>>>>> on
>>>>>>>>>
>>>>>>>>>  by default, but did not work for POST
>>>>>>>>>>
>>>>>>>>>>>  Looking for - HttpMethod#followRedirects() ?
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpMethod.html#setFollowRedirects%28boolean%29
>>>>>>>>>>
>>>>>>>>>> Cheers
>>>>>>>>>> Avlesh
>>>>>>>>>>
>>>>>>>>>> On Fri, Feb 19, 2010 at 1:23 PM, Andreas Blomqvist <
>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>
>>>>>>>>>>  Hi
>>>>>>>>>>
>>>>>>>>>>  Here some loggs from when I tried to logon:
>>>>>>>>>>>
>>>>>>>>>>>  [java] The server is running at http://localhost:8282/
>>>>>>>>>>>  [java] Got request method login
>>>>>>>>>>>  [java] 2010-feb-19 07:48:45
>>>>>>>>>>> org.apache.http.client.protocol.RequestAddCookies process
>>>>>>>>>>>  [java] FIN: CookieSpec selected: best-match
>>>>>>>>>>>  [java] 2010-feb-19 07:48:45
>>>>>>>>>>> org.apache.http.impl.client.DefaultRequestDirector execute
>>>>>>>>>>>  [java] FIN: Attempt 1 to execute request
>>>>>>>>>>>  [java] 2010-feb-19 07:48:46
>>>>>>>>>>> org.apache.commons.httpclient.HttpMethodDirector isRedirectNeeded
>>>>>>>>>>>  [java] INFO: Redirect requested but followRedirects is disabled
>>>>>>>>>>>
>>>>>>>>>>>  This log comes from HttpClient 3 (org.apache.commons.httpclient
>>>>>>>>>>> name
>>>>>>>>>>>
>>>>>>>>>> space), whereas all others come from HttpClient 4
>>>>>>>> (org.apache.http.client
>>>>>>>> name space).
>>>>>>>>
>>>>>>>> I have no idea what your application is supposed to do, but this
>>>>>>>> certainly
>>>>>>>> does not look right to me.
>>>>>>>>
>>>>>>>> Oleg
>>>>>>>>
>>>>>>>>
>>>>>>>>   [java] 2010-feb-19 07:48:46
>>>>>>>>
>>>>>>>>  org.apache.http.client.protocol.ResponseProcessCookies
>>>>>>>>> processCookies
>>>>>>>>>
>>>>>>>>>>  [java] FIN: Cookie accepted: "[version: 0][name:
>>>>>>>>>>> PHPSESSID][value:
>>>>>>>>>>> 9l8gtdf85tn4gitqjs0hg2f551][domain:
>>>>>>>>>>> schema.sthlm.friskissvettis.se
>>>>>>>>>>>
>>>>>>>>>>>  ][path:
>>>>>>>>>>>
>>>>>>>>>>  /][expiry: null]".
>>>>>>>>>>
>>>>>>>>>>>  [java] http://url_to_server/index.php?func=do_login
>>>>>>>>>>>  [java] 2010-feb-19 07:48:46
>>>>>>>>>>> org.apache.http.client.protocol.RequestAddCookies process
>>>>>>>>>>>  [java] FIN: CookieSpec selected: best-match
>>>>>>>>>>>  [java] 2010-feb-19 07:48:46
>>>>>>>>>>> org.apache.http.client.protocol.RequestAddCookies process
>>>>>>>>>>>  [java] FIN: Cookie [version: 0][name: PHPSESSID][value:
>>>>>>>>>>> 9l8gtdf85tn4gitqjs0hg2f551][domain:
>>>>>>>>>>> schema.sthlm.friskissvettis.se
>>>>>>>>>>>
>>>>>>>>>>>  ][path:
>>>>>>>>>>>
>>>>>>>>>>  /][expiry: null] match [
>>>>>>>>>> schema.sthlm.friskissvettis.se:80/index.php]
>>>>>>>>>>
>>>>>>>>>>>  [java] 2010-feb-19 07:48:46
>>>>>>>>>>> org.apache.http.impl.client.DefaultRequestDirector execute
>>>>>>>>>>>  [java] FIN: Attempt 1 to execute request
>>>>>>>>>>>  [java] 2010-feb-19 07:48:47
>>>>>>>>>>> org.apache.http.client.protocol.ResponseProcessCookies
>>>>>>>>>>> processCookies
>>>>>>>>>>>  [java] FIN: Cookie accepted: "[version: 0][name:
>>>>>>>>>>> PHPSESSID][value:
>>>>>>>>>>> 9tteoedfpeugqb81d2750dk3q5][domain:
>>>>>>>>>>> schema.sthlm.friskissvettis.se
>>>>>>>>>>>
>>>>>>>>>>>  ][path:
>>>>>>>>>>>
>>>>>>>>>>  /][expiry: null]".
>>>>>>>>>>
>>>>>>>>>>>  [java] 2010-feb-19 07:48:47
>>>>>>>>>>> org.apache.http.client.protocol.RequestAddCookies process
>>>>>>>>>>>  [java] FIN: CookieSpec selected: best-match
>>>>>>>>>>>  [java] 2010-feb-19 07:48:47
>>>>>>>>>>> org.apache.http.client.protocol.RequestAddCookies process
>>>>>>>>>>>  [java] FIN: Cookie [version: 0][name: PHPSESSID][value:
>>>>>>>>>>> 9tteoedfpeugqb81d2750dk3q5][domain:
>>>>>>>>>>> schema.sthlm.friskissvettis.se
>>>>>>>>>>>
>>>>>>>>>>>  ][path:
>>>>>>>>>>>
>>>>>>>>>>  /][expiry: null] match [
>>>>>>>>>> schema.sthlm.friskissvettis.se:80/index.php]
>>>>>>>>>>
>>>>>>>>>>>  [java] context:
>>>>>>>>>>> org.apache.http.protocol.basichttpcont...@148e798
>>>>>>>>>>>  [java] 2010-feb-19 07:48:47
>>>>>>>>>>> org.apache.http.impl.client.DefaultRequestDirector execute
>>>>>>>>>>>  [java] FIN: Attempt 1 to execute request
>>>>>>>>>>>  [java] 2010-feb-19 07:48:47
>>>>>>>>>>> org.apache.http.client.protocol.ResponseProcessCookies
>>>>>>>>>>> processCookies
>>>>>>>>>>>  [java] FIN: Cookie accepted: "[version: 0][name:
>>>>>>>>>>> PHPSESSID][value:
>>>>>>>>>>> 7ugatbbqeku112d8atm9b9qr34][domain:
>>>>>>>>>>> schema.sthlm.friskissvettis.se
>>>>>>>>>>>
>>>>>>>>>>>  ][path:
>>>>>>>>>>>
>>>>>>>>>>  /][expiry: null]".
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> It says redirect is disabled? How do enable it? I thought
>>>>>>>>>>> redirect was
>>>>>>>>>>> on
>>>>>>>>>>> by
>>>>>>>>>>> default, but did not work for POST
>>>>>>>>>>>
>>>>>>>>>>> /A
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 18 February 2010 21:17, Oleg Kalnichevski <[email protected]>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>  Andreas Blomqvist wrote:
>>>>>>>>>>>
>>>>>>>>>>>   Hi
>>>>>>>>>>>>
>>>>>>>>>>>>  Doing a POST login to a site (which I dont control) and
>>>>>>>>>>>>> manually
>>>>>>>>>>>>> redirecting. However I am not getting logged in until I make a
>>>>>>>>>>>>> second
>>>>>>>>>>>>>
>>>>>>>>>>>>>  call
>>>>>>>>>>>>>
>>>>>>>>>>>> to the login method. Why?
>>>>>>>>>>>>
>>>>>>>>>>>>  My code for login :
>>>>>>>>>>>>>
>>>>>>>>>>>>>  private HttpContext login(DefaultHttpClient httpClient, String
>>>>>>>>>>>>>
>>>>>>>>>>>>>  button,
>>>>>>>>>>>>>
>>>>>>>>>>>> String user, String pass) throws UnsupportedEncodingException,
>>>>>>>>>>>
>>>>>>>>>>>  IOException
>>>>>>>>>>>> {
>>>>>>>>>>>>
>>>>>>>>>>>>      HttpResponse response = null;
>>>>>>>>>>>>>     HttpEntity entity = null;
>>>>>>>>>>>>>     HttpPost httpost = new HttpPost(BASE_URL +
>>>>>>>>>>>>> "/index.php?func=do_login");
>>>>>>>>>>>>>
>>>>>>>>>>>>>     List<NameValuePair> nvps = new ArrayList<NameValuePair>();
>>>>>>>>>>>>>     nvps.add(new BasicNameValuePair("btn_login", button));
>>>>>>>>>>>>>     nvps.add(new BasicNameValuePair("txt_login", user));
>>>>>>>>>>>>>     nvps.add(new BasicNameValuePair("psw_password", pass));
>>>>>>>>>>>>>
>>>>>>>>>>>>>     httpost.setEntity(new UrlEncodedFormEntity(nvps,
>>>>>>>>>>>>> HTTP.UTF_8));
>>>>>>>>>>>>>
>>>>>>>>>>>>>     HttpContext context = new BasicHttpContext();
>>>>>>>>>>>>>     response = httpClient.execute(httpost, context);
>>>>>>>>>>>>>
>>>>>>>>>>>>>     System.out.println("Post status is " +
>>>>>>>>>>>>>
>>>>>>>>>>>>>  response.getStatusLine());
>>>>>>>>>>>>>     entity = response.getEntity();
>>>>>>>>>>>>>     if (entity != null) {
>>>>>>>>>>>>>         entity.consumeContent();
>>>>>>>>>>>>>     }
>>>>>>>>>>>>>
>>>>>>>>>>>>>     HttpUriRequest request = (HttpUriRequest)
>>>>>>>>>>>>> context.getAttribute(
>>>>>>>>>>>>>             ExecutionContext.HTTP_REQUEST);
>>>>>>>>>>>>>
>>>>>>>>>>>>>     String uri = BASE_URL + request.getURI().toString();
>>>>>>>>>>>>>
>>>>>>>>>>>>>     System.out.println("uri in login " + uri);
>>>>>>>>>>>>>
>>>>>>>>>>>>>     HttpGet redirect = new HttpGet(uri);
>>>>>>>>>>>>>     response = httpClient.execute(redirect, context);
>>>>>>>>>>>>>
>>>>>>>>>>>>>     System.out.println("Redirect HttpGet status is " +
>>>>>>>>>>>>> response.getStatusLine());
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>     entity = response.getEntity();
>>>>>>>>>>>>>     if (entity != null) {
>>>>>>>>>>>>>         entity.consumeContent();
>>>>>>>>>>>>>     }
>>>>>>>>>>>>>
>>>>>>>>>>>>>     return context;
>>>>>>>>>>>>>  }
>>>>>>>>>>>>>
>>>>>>>>>>>>> After a call to this method I get output: (checking login
>>>>>>>>>>>>> status is
>>>>>>>>>>>>>
>>>>>>>>>>>>>  method
>>>>>>>>>>>>>
>>>>>>>>>>>> I
>>>>>>>>>>>>
>>>>>>>>>>>>  made to check for att logout link on the page.
>>>>>>>>>>>>>
>>>>>>>>>>>>>  [java] Post status is HTTP/1.1 302
>>>>>>>>>>>>>  [java] uri in login url_to_first_page
>>>>>>>>>>>>>  [java] Redirect HttpGet status is HTTP/1.1 200
>>>>>>>>>>>>>  [java] Checking login statuts: false
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Any thoughts?
>>>>>>>>>>>>>
>>>>>>>>>>>>> /A
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>  Post wire log
>>>>>>>>>>>>>
>>>>>>>>>>>>>  http://hc.apache.org/httpcomponents-client/logging.html
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>>>> To unsubscribe, e-mail:
>>>>>>>>>>>> [email protected]
>>>>>>>>>>>> For additional commands, e-mail:
>>>>>>>>>>>> [email protected]
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>>>>
>>>>>>>>>>> To unsubscribe, e-mail:
>>>>>>>> [email protected]
>>>>>>>> For additional commands, e-mail:
>>>>>>>> [email protected]
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: [email protected]
>>>>>> For additional commands, e-mail: [email protected]
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [email protected]
>>>> For additional commands, e-mail: [email protected]
>>>>
>>>>
>>>
>>
>

Reply via email to