B4J Question WebView keep cookies

drgottjr

Expert
Licensed User
Longtime User
what do you mean by "keeping" a cookie? how do you know your login/password is a cookie? cookies function normally in a webview. you're not explaining everything that's going on. if you need to see exactly which cookies are being returned by a particular url, okhttputils2 does that easy. you can even send them back to the server. but not using a webview. using a webview involves some java code.
 
Upvote 0

ludogomez

Member
Licensed User
Longtime User
On the website I need to connect, I enter login and password, and after the website create a session cookie to prevent enter login and password again.
On my webview, I want to enter my login and password and keep the cookie to the next time I connect.

a webview is mandatory because user browse the website on this webview
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
it doesn't work that way. it's called a "session" cookie for a reason. you can't use it in a different session.
 
Upvote 0

ludogomez

Member
Licensed User
Longtime User
Yes I understand, but when I connect to the web page, I can click to remember my access, the website create a cookie on my harddisk and the next time I want to connect the website use this cookie to connect me without credentials.
I want to do the same with my webview.

Thanks
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
then it is not a session cookie. you say you understand, but i don't think you do. a session cookie will not be returned to the server in a different session. it's deleted.

a cookie that is not a session cookie (eg, a cookie which expires in 2021) is a normal cookie which the webview will return to the server like any other normal cookie.

do you know for a fact exactly what the server is returning? have you used okhttputils2 to look at the cookies?

also, it sounds like you are connecting to the website with your desktop browser. you then seem to say that you want to take the cookie from your desktop and use it in a webview? that's pretty wild. in any case, if a session cookie is involved, it's not going to work. (even if it's a normal unexpired cookie, it might not work; it depends on exactly what's in the cookie.)

so, if the cookie is not a session cookie, is there some reason you simply can't log in to the site with your webview and try to connect again with the webview to see if it works? i have no problem sending cookies back to the server with a webview. it happens automatically.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
What about saving your credentials locally on your device and using those next time?
You could set any rule you like (eg. how long the saved credentials will be valid, a checkbox to save/delete them..).
 
Upvote 0
Top