Re: [Httpunit-develop] Cookie Bug?
Brought to you by:
russgold
From: Torsten C. <tc...@ap...> - 2006-02-28 09:40:11
|
Do you still call "getCommentList" somewhere? Otherwise the Cookie handling is not getting set to lenient. Works for me even with more complicated sites quite well. HTH -- Torsten On 28.02.2006, at 12:04, William Saxton wrote: > George, got any answers for me? I think this was a better way of > asking my question, haha. > > On 2/22/06, William Saxton < sa...@gm...> wrote:Sorry all. > I've been away from this project for a while. Also, sorry for the > lack of information. Here's my code: > > public Comment[] getCommentList(String mui) throws Exception { > // TODO code application logic here > String url = "http://comments.myspace.com/index.cfm? > fuseaction=user.HomeComments&friendID=358314 "; > > HttpUnitOptions.setScriptingEnabled(false); > HttpUnitOptions.setExceptionsThrownOnScriptError(false); > //HttpUnitOptions.setLoggingHttpHeaders(true); > > CookieProperties.setDomainMatchingStrict(false); > CookieProperties.setPathMatchingStrict(false); > > WebConversation wc = new WebConversation(); > > ClientProperties cp = wc.getClientProperties(); > cp.setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en- > US; rv:1.7.6) Gecko/20050223 Firefox/1.0.1"); > cp.setAcceptCookies(true); > > wc.putCookie("MYUSERINFO", mui); > > WebResponse r = wc.getResponse(url); > > } > > When I login to the site using firefox, the http headers add-on I > have installed shows me the cookie value of MYUSERINFO as a 316 > char length string. When I run getCommentList(mui), where mui is > that string, the WebResponse I get is what I'm looking for. > > If I don't set the MYUSERINFO cookie value, I get a login page > saying I need to login first. > > Now, I'm trying to create a program that automatically logs in. I > created a "Loginer" class to do so: > > public class Loginer { > > private String loginURL = "http://www.myspace.com/index.cfm? > fuseaction=splash "; > private String loginName = "sa...@gm..."; > private String loginPassword = "******"; > private String myUserInfo; > > /** Creates a new instance of Loginer */ > public Loginer() { > > } > > public void login() throws Exception { > > HttpUnitOptions.setScriptingEnabled(false); > HttpUnitOptions.setExceptionsThrownOnScriptError(false); > > WebConversation wc = new WebConversation(); > > ClientProperties cp = wc.getClientProperties(); > cp.setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; > en-US; rv:1.7.6) Gecko/20050223 Firefox/1.0.1"); > cp.setAcceptCookies(true); > > System.out.println("---Attempting to access login page---"); > > WebResponse r = wc.getResponse(loginURL); > > WebForm wf[] = r.getForms(); > WebForm loginForm = wf[1]; > String cookieList[] = r.getNewCookieNames(); > System.out.println("Prelogin"); > System.out.println("Cookie: Cookie Value"); > for (int i=0;i<cookieList.length;i++) { > System.out.println(cookieList[i] + ":" + > r.getNewCookieValue(cookieList[i])); > } > > loginForm.setParameter("email", loginName); > loginForm.setParameter("password", loginPassword); > > WebResponse loginwr = loginForm.submit(); > > String newCookieList[] = loginwr.getNewCookieNames(); > System.out.println("Postlogin"); > System.out.println("Cookie: Cookie Value"); > for (int i=0;i<newCookieList.length;i++) { > System.out.println(newCookieList[i] + ":" + > r.getNewCookieValue(newCookieList[i])); > } > > } > > When I run the 'login' method, I get the following: > > Gets me the following output; > ---Attempting to access login page--- > Prelogin > Cookie: Cookie Value > Postlogin > Cookie: Cookie Value > MYUSERINFO:null > > Would any other information be useful? Seems to me this websites > login interface is pretty simple, so that setting the input box > values and submitting the form should be all that is necessary to > get this MYUSERINFO cookie value. > > > > > On 1/27/06, Geo...@we... < > Geo...@we...> wrote: > "It seems to me there is a string length issue with cookies." What > have you done to localize the problem? Your query doesn't give any > indication that your issue is in HTTPUnit. Do you have a simple > test you can share with others? Have you read http://www.catb.org/ > ~esr/faqs/smart-questions.html ? > > "Is this a known issue?" Not as far as I know. > > "Any workaround?" Probably. > > > William Saxton asked: > Hi all, > > When I log into a certain website, I receive a 316 char string in > a cookie value. If I set the cookie manually, using wc.putCookie, > my httpunit program functions as if the cookie has been set. > > If I try to retreive the cookie value through the actual program > (using getNewCookieValue), the String comes back as 0 length. All > the other cookies are fine. > > It seems to me there is a string length issue with cookies. Is > this a known issue? Any workaround? > > -Bill > > |