Search code examples
androidcookieswebviewhttp-request

Perform HTTP requests using cookies from webview


I have this scenario which my app shows in a webView a 2-page login process.

The first page asks only to which domain to you plan on connecting. The second page asks for the credentials.

I'm trying to perform the login in the webView and then execute requests from my native code. I realize I need to get the stored cookie from the webView (but from which url? from the first page or the second one?), and then use the cookie for the native code requests.

Can someone please tell me how to go about it? The login process is easy - the user logs in through the webview - fine. Now, I know how to use the cookie manage but I dont know which cookie am I suppose to look for - is it the url of the first login page? is it the second one? does it matter?

Next, how do I use the cookie to send back to server with a GET request so the server will know I'm authenticated?

I appreciate the answers I'm clueless and begging for help :)


Solution

  • At the end I found my way and it was pretty simple.

    Once the user logs in through the webview - a cookie is set on the device. Later on once I want to perform Native api calls on the service I ask the cookie manager for the cookie that was set based on the url.

    I then take the important header that is used to authenticate on the server and send it along with my api calls.