hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kalnichevski, Oleg" <oleg.kalnichev...@bearingpoint.com>
Subject RE: Cookie Problem
Date Mon, 16 Feb 2004 14:10:40 GMT
Hi Hareesh,

None of the cookie specs in the stable (HttpClient 2.0) branch can handle malformed cookies
with unescaped commas. The development branch (HttpClient 3.0-pre-alpha) contains an improved
Netscape cookie spec capable of handling commas in cookie values. For more details on the
problem refer to the bug report below:

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11240

Oleg

-----Original Message-----
From: hareesh babu [mailto:hareeshyv@yahoo.co.in]
Sent: Monday, February 16, 2004 13:37
To: Commons HttpClient Project
Cc: ROLWEBER@de.ibm.com
Subject: Re: Cookie Problem


Hi  Roland Weber,

  Thanks for you immediate reponse. Even if set the
cookie policy by different i am getting the problem. 
Let me explain the problem i am facing, I am sending a
get request the home page of the xxx website, it is
comming fine, after that i am sending a post with user
and password, and that is also comming after that if
send a another get request in the internal site which
requies authorized user, website is checking the
cookie, but the cookie problem, the website is
redirecting the request into home page one agian. 
I try do by removing the SEPARATORS.set(',');  in the
HeaderElement, no use. 
  
Here i placing my sample request program

*****************************

import java.io.IOException;
import java.net.MalformedURLException;
import org.apache.commons.httpclient.Credentials;
import
org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.Cookie;
import
org.apache.commons.httpclient.cookie.CookiePolicy;
import
org.apache.commons.httpclient.methods.GetMethod;
import
org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.Header;


public class Test1
{

     public static void main(String[] args) throws
Exception
    {
       
System.setProperty("org.apache.commons.logging.Log",
"org.apache.commons.logging.impl.SimpleLog");
       
System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
"true");
       
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire",
"debug");
       
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
"debug");
      

        //create a singular HttpClient object
        String HOST ="yyyy.xxx.com";
        int PORT = 80;

        HttpClient client = new HttpClient();
        client.getHostConfiguration().setHost(HOST,
PORT, "http");
        client.getState().setCookiePolicy(
CookiePolicy.COMPATIBILITY );


        String url = "/online/on_login1.jsp";
        GetMethod getMethod = null;
        Header header1 = new Header ("Accept",
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/msword, */*");
        Header header2 = new Header ("Referer",
"http://" + HOST);
        Header header3 = new Header
("Accept-Language", "en-us");
        Header header4 = new Header  ("Content-Type",
"application/x-www-form-urlencoded");
        Header header5 = new Header
("Accept-Encoding", "gzip, deflate");
        Header header6 = new Header
("Proxy-Connection", "Keep-Alive");
        Header header7 = new Header ("Pragma",
"no-cache");
        Header header8 = new Header ("Cookie",
"name=Online");

        getMethod = new GetMethod(url);
        getMethod.setFollowRedirects(true);
        getMethod.setStrictMode(false);
        getMethod.setRequestHeader(header1);
        getMethod.setRequestHeader(header2);
        getMethod.setRequestHeader(header3);
        getMethod.setRequestHeader(header4);
        getMethod.setRequestHeader(header5);
        getMethod.setRequestHeader(header6);
        getMethod.setRequestHeader(header7);
        getMethod.setRequestHeader(header8);

        //execute the method
        String responseBody = null;
        try{
            client.executeMethod(getMethod);
            responseBody =
getMethod.getResponseBodyAsString();
        } catch (HttpException he) {
            System.err.println("Http error connecting
to '" + url + "'");
            System.err.println(he.getMessage());
            System.exit(-4);
        } catch (IOException ioe){
            System.err.println("Unable to connect to
'" + url + "'");
            System.exit(-3);
        }

        Cookie[] logoncookies =
client.getState().getCookies(HOST, PORT, "/", false);
        System.out.println("First Request Cookies");
        if (logoncookies.length == 0) {
            System.out.println("None");
        } else {
            for (int i = 0; i < logoncookies.length;
i++) {
                System.out.println("- " +
logoncookies[i].toString());
            }
        }

        //write out the request headers
        System.out.println("*** Request ***");
        System.out.println("Request Path: " +
getMethod.getPath());
        System.out.println("Request Query: " +
getMethod.getQueryString());
        Header[] requestHeaders =
getMethod.getRequestHeaders();
        for (int i=0; i<requestHeaders.length; i++){
            System.out.print(requestHeaders[i]);
        }

        //write out the response headers
        System.out.println("*** Response ***");
        System.out.println("Status Line: " +
getMethod.getStatusLine());
        Header[] responseHeaders =
getMethod.getResponseHeaders();
        for (int i=0; i<responseHeaders.length; i++){
            System.out.print(responseHeaders[i]);
        }

        //write out the response body
         System.out.println("*** Response Body ***");
        System.out.println(responseBody);

        //clean up the connection resources
        getMethod.releaseConnection();
        getMethod.recycle();



        NameValuePair[] formData = new
NameValuePair[3];
        formData[0] = new NameValuePair ("username",
"aaaa");
        formData[1] = new NameValuePair ("password",
"bbbb");
        formData[2] = new NameValuePair
("edit_userpass", "Entery");

        PostMethod postMethod = new
PostMethod("/online/on_login1.jsp");
        postMethod.setFollowRedirects(true);
        postMethod.setStrictMode(false);
        postMethod.addParameters(formData);
        postMethod.setRequestHeader(header1);
        //postMethod.setRequestHeader(header2);
        postMethod.setRequestHeader(header3);
        postMethod.setRequestHeader(header4);
        postMethod.setRequestHeader(header5);
        postMethod.setRequestHeader(header6);
        postMethod.setRequestHeader(header7);


        client.executeMethod(postMethod);
        responseBody =
postMethod.getResponseBodyAsString();
        System.out.println("Login form post: " +
postMethod.getStatusLine().toString());
        // release any connection resources used by
the method

        logoncookies =
client.getState().getCookies(HOST, PORT, "/", false);
        System.out.println("Logon cookies:");
        if (logoncookies.length == 0) {
            System.out.println("None");
        } else {
            for (int i = 0; i < logoncookies.length;
i++) {
                System.out.println("- " +
logoncookies[i].toString());
            }
        }

        //write out the request headers
        System.out.println("*** Request ***");
        System.out.println("Request Path: " +
postMethod.getPath());
        System.out.println("Request Query: " +
postMethod.getQueryString());
        requestHeaders =
postMethod.getRequestHeaders();
        for (int i=0; i<requestHeaders.length; i++){
            System.out.print(requestHeaders[i]);
        }

        //write out the response headers
        System.out.println("*** Response ***");
        System.out.println("Status Line: " +
postMethod.getStatusLine());
        responseHeaders =
postMethod.getResponseHeaders();
        for (int i=0; i<responseHeaders.length; i++){
            System.out.print(responseHeaders[i]);
        }

        //write out the response body
        System.out.println("*** Response Body ***");
        System.out.println(responseBody);

        postMethod.releaseConnection();
        postMethod.recycle();

        System.out.println ("successfully logged
in\n");

        System.out.print ("Passing thru intermediate
screen - I ...");

        GetMethod getMethod1 = null;

        getMethod1 = new
GetMethod("/online/jsp/onlinestyle/on_login1.jsp");
        getMethod1.setFollowRedirects(true);
        getMethod1.setStrictMode(false);
        getMethod1.setRequestHeader(header1);
       // getMethod1.setRequestHeader(header2);
        getMethod1.setRequestHeader(header3);
        getMethod1.setRequestHeader(header4);
        getMethod1.setRequestHeader(header5);
        getMethod1.setRequestHeader(header6);
        getMethod1.setRequestHeader(header7);

        client.executeMethod(getMethod1);

        responseBody =
getMethod1.getResponseBodyAsString();
        System.out.println("After Login next get
method: " + getMethod1.getStatusLine().toString());

        //write out the request headers
        System.out.println("*** Request ***");
        System.out.println("Request Path: " +
getMethod1.getPath());
        System.out.println("Request Query: " +
getMethod1.getQueryString());
        requestHeaders =
getMethod1.getRequestHeaders();
        for (int i=0; i<requestHeaders.length; i++){
            System.out.print(requestHeaders[i]);
        }

        //write out the response headers
        System.out.println("*** Response ***");
        System.out.println("Status Line: " +
getMethod1.getStatusLine());
        responseHeaders =
getMethod1.getResponseHeaders();
        for (int i=0; i<responseHeaders.length; i++){
            System.out.print(responseHeaders[i]);
        }

        //write out the response body
        System.out.println("*** Response Body ***");
        System.out.println(responseBody);

        //clean up the connection resources
        getMethod1.releaseConnection();
        getMethod1.recycle();

        System.out.println("done");
        System.exit(0);
    }
}
888888888888888888888888888888888
 

Can u suggest me any solution.
Hareesh.

 

--- Roland Weber <ROLWEBER@de.ibm.com> wrote: > Hello
Hareesh,
> 
> the cookie shouldn't include commas in the first
> place,
> that's a violation of the respective specification.
> But
> since you have to access that page, try setting a
> different cookie policy. Check out the options in
> org.apache.commons.httpclient.cookie.CookiePolicy
> 
> Try NETSCAPE and BROWSER_COMPATIBILITY.
> 
> cheers,
>   Roland
> 
> 
> 
> 
> 
> 
> 
> hareesh babu <hareeshyv@yahoo.co.in>
> 16.02.2004 12:21
> Please respond to "Commons HttpClient Project"
>  
>         To:    
> commons-httpclient-dev@jakarta.apache.org
>         cc: 
>         Subject:        Cookie Problem
> 
> 
> Hi, 
> 
> I am working on xxxx website using apache commons
> library of http client.
> 
> I was able to login into the xxxx website using my
> code and not able navigate into xxxx website.
> 
> I was facing one problem with apache http client at
> cookie assumption.
> 
> xxxx website is sending cookie like this way,
> Set-Cookie:
> usr2_xxxx_com=jzu,aa,czj,dm;path=/;domain=.xxxx.com;
> 
> But apache http client is dividing the cookie into
> 4.
> "Cookie: usr2_xxx_com=jzu[\r][\n]"
> "Cookie: aa=[\r][\n]"
> "Cookie: czj=[\r][\n]"
> "Cookie:
>
ON_VAT2=@@@@103556810351170501155924063287@@@@[\r][\n]"
> "Cookie: dm=[\r][\n]"
> 
> So next when I send a new get method it sending the
> xxxx website 4 cookies instead of one.
> 
> I am thinking due this problem I was not able to
> navigate into xxxx website.
> 
> Http client lib i am working on
>
http://mirrors.xtria.com/apache/jakarta/commons/httpclient/source/commons-httpclient-2.0-rc3-src.zip
> 
> 
> Suggest me if am thinking right.
> 
> Hareesh.
> 
>
________________________________________________________________________
> Yahoo! India Insurance Special: Be informed on the
> best policies, 
> services, tools and more. 
> Go to:
> http://in.insurance.yahoo.com/licspecial/index.html
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail: 
>
commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
> 
> 
>  

________________________________________________________________________
Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more.

Go to: http://in.insurance.yahoo.com/licspecial/index.html

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Mime
View raw message