成功登录后,我试图访问一个网页,在那里我获得了用户名和密码(从我的应用程序中的 EditTexts“user = (EditText) findViewById(R.id.user);”和“pass = (EditText) findViewById (R.id.pass);" ) 并将其发布到服务器。
问题是 webview 仅在具有 android 4.2.2 但在 4.4.2、4.4.4 和 5.0.1 上正常工作的手机/平板电脑上显示文本“需要授权....”(成功登录后) (显示预期的页面)。
我的想法不多了,需要帮助。你们能帮帮我吗?先感谢您。
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("user", user.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("password", pass.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
httppost.addHeader("Authorization", "Basic BLA123BLA23BLA32343LSJ");
// Execute HTTP Post Request
response = httpclient.execute();
//WebView
webview_asd = new WebView(MainScreen.this);
webview_asd = (WebView) findViewById(R.id.webview_asd);
webview_asd.getSettings().setLoadsImagesAutomatically(true);
webview_asd.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webview_asd.setWebViewClient( new WebViewClient() );
webview_asd.getSettings().setJavaScriptEnabled(true);
CookieSyncManager.createInstance (webview_asd.getContext());
CookieSyncManager.getInstance().sync();
cookies = ((AbstractHttpClient) httpclient).getCookieStore().getCookies();
if(cookies != null)
{
for(Cookie cookie : cookies)
{
cookieString = cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain();
CookieManager.getInstance().setCookie(cookie.getDomain(), cookieString);
}
}
CookieSyncManager.getInstance().sync();
webview_asd.loadURL(URL);
webview_asd.setVisibility(View.VISIBLE);
webview 页面显示“需要授权。此服务器无法验证您是否有权访问所请求的文档。您提供了错误的凭据(例如,密码错误),或者您的浏览器不了解如何提供所需的凭据。 "
稍后编辑:刚刚发现 4.2.2 不支持 HTML5,这就是我遇到这个问题的原因。