tags:

views:

33

answers:

1

Hello! I have trouble passing the cookie into the WebView inject. I know how to inject the cookie. When the cookie is injected I want to display a member.php and this page requires a cookie. It shows me the error page even if I've injected the cookie.

The WebView are correctly loaded and I've tried to set a cookie using the CookieManager class. Alll this is known to me.

From the CookieStore I have tried to print out the whole cookie itself; which prints this:

[[version: 0][name:SQMSESSID][value: 9166729532c975f261bda9e6e583bdba]
[domain: mydomain.com][path: /][expiry: null], [version: 0][name: key]
[value: vrckNRab][domain: mydomain.com][path: /][expiry: null]]

Should be mentioned that the code above is the successful CookieStore when I have passed my correct username and password.

My inject + loadUrl code:

CookieStore cookie = /* CookieStore cookie takes a CookieStore from my 
own function that succesful returns the CookieStore */
List<Cookie> listcookie = cookie.getCookies(); //Set my CookieStore to a list
Cookie setcookieOne = listcookie.get(0) //My cookie has two fields
Cookie setcookieTwo = listcookie.get(1) //....and assign these to a cookie

 CookieManager cookieManager = CookieManager.getInstance(); 
CookieSyncManager.createInstance(getApplicationContext());
cookieManager.setAcceptCookie(true);
 cookieManager.setCookie(setcookieOne.getDomain(), setcookieOne.getValue()); 
    cookieManager.setCookie(setcookieTwo.getDomain(), setcookieTwo.getValue()); 
  CookieSyncManager.getInstance().sync();
browse.setWebViewClient(new WebViewClient(){
}); 
browse.loadUrl("http://mypagethatwillredirectmeonacorrectcookie.php"); /* This
page will redirect if the cookie is successful */

Any ideas why it doesn't show the member.php?

+1  A: 

First, make sure that getValue() on a Cookie returns what setCookie() on a CookieManager requires. CookieManager needs "The value for set-cookie: in http response header"; Cookie's getValue() I suspect returns only the actual value (9166729532c975f261bda9e6e583bdba in your example).

Second, never use getApplicationContext(), particularly for GUI operations. Use your Activity instead, since Activity is a subclass of Context.

CommonsWare
Okay, deleted the previous comment since new info appeared. Now I'm using the getHeaders("Set-cookie") and it returns: "`[Lorg.apache.http.Header;@412414ab141]´". I have tried to pass this into the setCookie method, but still it doesn't work.
Julian Assange
Should be mentioned that when I look in Wireshark. There is no Set-Cookie under the Hypertext Transfer Protocol. The closest is "Cookie".
Julian Assange
@Julian Assange: You need a LOT more HTTP experience if you are going to try writing software like this. There most certainly is a `Set-Cookie` header in HTTP responses, and it has been there for the better part of 15 years. http://en.wikipedia.org/wiki/HTTP_cookie `getHeaders("Set-cookie")` is returning an array of `Header` objects.
CommonsWare
Well, I know that if I'm going to write stuff like this I better learn HTTP in the depth. Though is this the only needed function, then no more of this at all. However, I'm stuck in this. But do you know if the returned value I got from "Set-Cookie" is on the correct way?
Julian Assange
In HTTP Debugger I found the Set-Cookie field, so now can I get the correct values.
Julian Assange
Okey, the Set-Cookie field from my HttpDebugger is: _"SQMSESSID=39d41f86b9c8bad04c9253040616ff07; path=/"_. I also take out the nescessary info from my cookie and I get it prints the cookie info in a Toast and it is equivalent to the Set-Cookie field in my HttpDebugger, but still I don't get logged in...
Julian Assange
@Julian Assange: In one of your other SO questions on this subject, it looked like there were a total of five cookies being returned. You should be able to confirm this -- you should have five elements in the array of `Header` objects. If the only one you're now injecting is `SQMSESSID`, that is perhaps necessary, but not sufficient. Try finding and setting all five, or however many there are in the `Header` array.
CommonsWare
Got it tow work, there were multiple Set-Cookie fields which I don't catch up! THank you! Now to, what du you mean with that I should use my activity instead? My current solution with the headers are to check the Set-Cookie response manually.
Julian Assange
@Julian Assange: "Now to, what du you mean with that I should use my activity instead?" -- delete `getApplicationContext()` and replace with `this`. `getApplicationContext()` is a dangerous little method and should be avoided wherever possible.
CommonsWare
Thank you! I really appreciate your support to the community.
Julian Assange