Here is how I did it:

1. derive your own method from the one you want to use - e.g.:

    class MyGetMethod extends GetMethod {
        .. constructors...
    protected void processResponseHeaders (HttpState state, HttpConnection
conn)

    {

    final HeaderGroup hg=getResponseHeaderGroup();

    Header[] headers=hg.getHeaders("set-cookie2");

    // Process old style set-cookie headers if new style headres are not
present

    if ((null == headers) || (headers.length <= 0))

headers = hg.getHeaders("set-cookie");

final CookieSpec
parser=CookiePolicy.getSpecByPolicy(state.getCookiePolicy());

for (int i = 0; i < headers.length; i++)

{

final Header header=headers[i];

/* NOTE !!! remove the header from the group since we

* handle it here, and then we call the base class

*/

hg.removeHeader(header);

Cookie[] cookies=null;

try

{

cookies = parser.parse(

conn.getHost(),

conn.getPort(),

getPath(),

conn.isSecure(),

header);

}

catch (MalformedCookieException e)

{

// ignore

}

if (cookies != null)

{

for (int j = 0; j < cookies.length; j++)

{

final Cookie cookie=cookies[j];

try

{

/* NOTE !!! overridden this check in the

* default "validate" since serversends

* such cookies. In this case, we take a chance

* and accumulate the cookie anyway

*/

if (getPath().startsWith(cookie.getPath()))

parser.validate(conn.getHost(),

conn.getPort(),

getPath(),

conn.isSecure(),

cookie);

state.addCookie(cookie);

}

catch (MalformedCookieException e)

{

// ignore

}

}

}

}

/* NOTE: we call the base class even though it is a waste of

* time since the above code is what the base class does (except

* for the special adjustments). However, better safe than sorry,

* just in case future implementations do something else as well.

*/

super.processResponseHeaders(state, conn);

} // end of processResponseHeaders method override

    }

----- Original Message ----- 
From: "Kalnichevski, Oleg" <[EMAIL PROTECTED]>
To: "Commons HttpClient Project" <[EMAIL PROTECTED]>
Sent: Wednesday, July 21, 2004 11:18
Subject: RE: how to accept all cookies ?



Mathias,

I know it is of little comfort to you but the cookie clearly violates even
the most loosely defines HTTP security policies. At least the site seems to
send the invalid cookie to MSIE (or any agent identifying itself as MSIE)
only

I see three possibilities to solve the problem

(1) I _assume_ that the host www.altavista.com may aslo have a DNS entry
within the yahoo.com domain. See if can find it out and use it instead
(2) provide a custom cookie policy. Unfortunately pluggable cookie policies
are supported by HttpClient 3.0 only, which is still in ALPHA
(3) Get HttpClient 2.0 source code and tweak it to your liking

Oleg


-----Original Message-----
From: Mathias Cianci [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 21, 2004 10:38
To: Commons HttpClient Project
Subject: Re: how to accept all cookies ?


Thank you Oleg, now it works !

But I still have another cookie problem :-(

Altavista have recently been acquired by Yahoo corp.
When you make requests in atltavista.com, you're now transparently
redirected to  yahoo.com (whitch puts a cookie for the domain
altavista.com), and then again to altavista.com.
As a result of this redirection, I get this warning message :

21 juil. 2004 10:26:52 org.apache.commons.httpclient.HttpMethodBase
processResponseHeaders
ATTENTION: Cookie rejected: "B=f24p1390fsa6m&b=2". Illegal domain
attribute ".yahoo.com". Domain of origin: "fr.altavista.com"

How can I accept this cookie transparently ?

Mathias

Kalnichevski, Oleg a écrit :

>Replace
>
>
>  System.setProperty("httpclient.cookiespec", "COMPATIBILITY");
>
>with
>
>  HttpClient client = new HttpClient();
>  client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY);
>
>and see if that makes any difference.
>
>Oleg
>
>-----Original Message-----
>From: Mathias Cianci [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, July 21, 2004 10:19
>To: Commons HttpClient Project
>Subject: Re: how to accept all cookies ?
>
>
>Thank you for this answer, but I've already seen that :-(
>
>Here's a part of my source code :
>
>        System.getProperties().setProperty("httpclient.useragent",
>
>"Mozilla/4.0 (compatible; MSIE 6.0; Windows XP)");
>        System.setProperty("httpclient.cookiespec", "COMPATIBILITY");
>
>        HttpClient client = new HttpClient();
>
>
>        HttpMethod method = new GetMethod(adresse);
>        method.setRequestHeader("Accept-Language","fr");
>        method.setRequestHeader("Accept-Charset", "UTF-8");
>
>Mathias
>
>Kalnichevski, Oleg a écrit :
>
>
>
>>Mathias,
>>
>>Try using the browser compatibility cookie policy. For details please
refer to the HttpClient cookie guide:
>>
>>http://jakarta.apache.org/commons/httpclient/cookies.html
>>
>>Oleg
>>
>>
>>
>>-----Original Message-----
>>From: Mathias Cianci [mailto:[EMAIL PROTECTED]
>>Sent: Wednesday, July 21, 2004 9:58
>>To: [EMAIL PROTECTED]
>>Subject: how to accept all cookies ?
>>
>>
>>Hello everybody,
>>
>>When I'm sending requests to Yahoo search engine, I get this type of
>>
>>warning message :
>>
>>21 juil. 2004 09:56:32 org.apache.commons.httpclient.HttpMethodBase
>>
>>processResponseHeaders
>>ATTENTION: Cookie rejected: "$Version=0; B=deli0110fs8dr&b=2;
>>
>>$Domain=.yahoo.com; $Path=/". Domain attribute ".yahoo.com" violates RFC
>>
>>2109: host minus domain may not contain any dots
>>
>>
>>Does someone know how I can accept every cookie I receive, even if they
>>
>>are not completly respect the official specifications ?
>>
>>Thank you for advance
>>
>>Mathias
>>
>>
>>
>>
>>**************************************************************************
*************************
>>The information in this email is confidential and may be legally
privileged.  Access to this email by anyone other than the intended
addressee is unauthorized.  If you are not the intended recipient of this
message, any review, disclosure, copying, distribution, retention, or any
action taken or omitted to be taken in reliance on it is prohibited and may
be unlawful.  If you are not the intended recipient, please reply to or
forward a copy of this message to the sender and delete the message, any
attachments, and any copies thereof from your system.
>>**************************************************************************
*************************
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail:
[EMAIL PROTECTED]
>>For additional commands, e-mail:
[EMAIL PROTECTED]
>>
>>
>>
>>
>>
>>
>
>
>
>
>
>***************************************************************************
************************
>The information in this email is confidential and may be legally
privileged.  Access to this email by anyone other than the intended
addressee is unauthorized.  If you are not the intended recipient of this
message, any review, disclosure, copying, distribution, retention, or any
action taken or omitted to be taken in reliance on it is prohibited and may
be unlawful.  If you are not the intended recipient, please reply to or
forward a copy of this message to the sender and delete the message, any
attachments, and any copies thereof from your system.
>***************************************************************************
************************
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail:
[EMAIL PROTECTED]
>For additional commands, e-mail:
[EMAIL PROTECTED]
>
>
>
>
>


****************************************************************************
***********************
The information in this email is confidential and may be legally privileged.
Access to this email by anyone other than the intended addressee is
unauthorized.  If you are not the intended recipient of this message, any
review, disclosure, copying, distribution, retention, or any action taken or
omitted to be taken in reliance on it is prohibited and may be unlawful.  If
you are not the intended recipient, please reply to or forward a copy of
this message to the sender and delete the message, any attachments, and any
copies thereof from your system.
****************************************************************************
***********************

---------------------------------------------------------------------
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