简体   繁体   English

Android Studio:显示需要登录WebView的网页

[英]Android Studio: Showing web page that requires login in WebView

I try to show part of a webpage using webview and the SELECT function of Jsoup. 我尝试使用webview和Jsoup的SELECT函数显示部分网页。 It works when we select a class from a regular HTML page and then do a "loadData" to the WebView. 当我们从常规HTML页面中选择一个类,然后对WebView执行“ loadData”操作时,它就可以工作。 However, if the page has login it doesn't show anything. 但是,如果页面已登录,则不会显示任何内容。 Even, if we try to login first using "loadURL" into the WebView and logging in with the user and password, and only then do a "loadData" to the same page it doesn't work. 即使,如果我们尝试首先使用“ loadURL”登录到WebView中并使用用户名和密码登录,然后才在同一页面上执行“ loadData”,则该页面将不起作用。 Is there an example showing how to handle pages that have login? 有没有显示如何处理已登录页面的示例?

The reason why it's not properly logging you in is because you don't store cookies with your Webview. 之所以无法正确登录,是因为您没有在Webview中存储cookie。 When you login, there's likely a session cookie stored that authenticates the user. 登录时,可能会存储用于验证用户身份的会话Cookie。 If it's not enabled, the user can't stay logged in between pages. 如果未启用,则用户将无法在页面之间保持登录状态。

See this on how to enable cookies in a webview. 请参见关于如何启用Cookie在网页视图。 You are using the CookieManager in android to do this. 您正在使用android中的CookieManager来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM