android中webview/webviewclient截获401响应
来源:互联网 发布:asd a0421 ab软件 编辑:程序博客网 时间:2024/06/09 12:43
代码片段(5)[全屏查看所有代码]
1. [代码]a.jsp (结果可以触发onReceivedHttpAuthRequest事件)
1
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2
pageEncoding="ISO-8859-1"%>
3
<% response.setStatus(401,"authen required"); %>
4
<% response.addHeader("WWW-Authenticate","Basic realm="Secure Area a""); %>
5
<
html
>
6
<
body
>
7
test.
8
</
body
>
9
</
html
>
2. [代码]b.jsp 结果不能触发事件
1
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2
pageEncoding="ISO-8859-1"%>
3
<% response.setStatus(401,"authen required"); %>
4
<% response.addHeader("WWW-Authenticate","MyAuth realm="Secure Area b""); %>
5
<
html
>
6
<
body
>
7
test
8
</
body
>
9
</
html
>
3. [代码]c.jsp 结果可以触发该事件!!
1
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2
pageEncoding="ISO-8859-1"%>
3
<% response.setStatus(401,"authen required"); %>
4
<% response.addHeader("WWW-Authenticate","TestBasic realm="Secure Area c",a=b"); %>
5
<
html
>
6
<
body
>
7
test.
8
</
body
>
9
</
html
>
4. [代码]d.jsp 结果可以触发该事件。(说明:http规范容许多种认证方式同时支持。)
01
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
02
pageEncoding="ISO-8859-1"%>
03
<% response.setStatus(401,"authen required"); %>
04
<% response.addHeader("WWW-Authenticate","MyAuth realm="Secure Area d""); %>
05
<% response.addHeader("WWW-Authenticate","Basic realm="Secure Area d""); %>
06
<
html
>
07
<
body
>
08
test
09
</
body
>
10
</
html
>
5. [代码]Main.java
01
package
com.my.example;
02
03
import
android.app.Activity;
04
import
android.app.AlertDialog;
05
import
android.app.ProgressDialog;
06
import
android.content.DialogInterface;
07
import
android.content.Intent;
08
import
android.net.Uri;
09
import
android.os.Bundle;
10
import
android.util.Log;
11
import
android.view.Window;
12
import
android.webkit.WebSettings;
13
import
android.webkit.WebView;
14
import
android.webkit.WebViewClient;
15
import
android.widget.Toast;
16
import
android.webkit.HttpAuthHandler;
17
18
public
class
Main
extends
Activity {
19
private
WebView webview;
20
private
static
final
String TAG =
"Main"
;
21
private
ProgressDialog progressBar;
22
23
24
@Override
25
public
void
onCreate(Bundle savedInstanceState) {
26
super
.onCreate(savedInstanceState);
27
28
requestWindowFeature(Window.FEATURE_NO_TITLE);
29
30
setContentView(R.layout.main);
31
32
this
.webview = (WebView)findViewById(R.string.webview);
33
34
WebSettings settings = webview.getSettings();
35
settings.setJavaScriptEnabled(
true
);
36
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
37
38
final
AlertDialog alertDialog =
new
AlertDialog.Builder(
this
).create();
39
40
progressBar = ProgressDialog.show(Main.
this
,
"Example"
,
"Loading..."
);
41
42
webview.setWebViewClient(
new
WebViewClient() {
43
public
boolean
shouldOverrideUrlLoading(WebView view, String url) {
44
Log.i(TAG,
"Processing webview url click..."
);
45
view.loadUrl(url);
46
return
true
;
47
}
48
49
public
void
onPageFinished(WebView view, String url) {
50
Log.i(TAG,
"Finished loading URL: "
+url);
51
if
(progressBar.isShowing()) {
52
progressBar.dismiss();
53
}
54
}
55
56
public
void
onReceivedError(WebView view,
int
errorCode, String description, String failingUrl) {
57
Log.e(TAG,
"Error: "
+ description);
58
// Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
59
alertDialog.setTitle(
"Error"
);
60
alertDialog.setMessage(description);
61
alertDialog.setButton(
"OK"
,
new
DialogInterface.OnClickListener() {
62
public
void
onClick(DialogInterface dialog,
int
which) {
63
return
;
64
}
65
});
66
alertDialog.show();
67
}
68
69
70
public
void
onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
71
72
alertDialog.setTitle(
"Error"
);
73
alertDialog.setMessage(host+view.getUrl());
74
alertDialog.setButton(
"OK"
,
new
DialogInterface.OnClickListener() {
75
public
void
onClick(DialogInterface dialog,
int
which) {
76
return
;
77
}
78
});
79
alertDialog.show();
80
}
81
82
});
83
webview.loadUrl(
"http://192.168.0.103:8080/web01/d.jsp"
);
84
}
85
}
举报
0 0
- android中webview/webviewclient截获401响应
- Android中WebView,WebViewClient,WebChromeClient区别
- Android WebView中的WebViewClient
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中WebView方法WebViewClient和WebChromeClient的区别
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- Android中使用WebView, WebChromeClient和WebViewClient加载网页
- android WebView(三)WebViewClient
- android.webkit.WebView/WebViewClient/WebChromeClient
- android的WebView、WebViewClient、WebChromeClient的关系
- DP 之 poj 3280
- 翻纸牌游戏 贪心
- 黑马程序员——【Java】【高新技术】自定义动态代理,过程、DEMO
- 黑马程序员——【Java】【高新技术】代理作用、原理、AOP
- Android学习笔记(十五)自定义控件(declare-styleable 的使用)
- android中webview/webviewclient截获401响应
- DP 之 poj 2955
- GitHub入门之一:使用github下载项目
- 黑马程序员 自学0304C#编程基础之类型的转换与转型
- 初识UML
- 黑马程序员——【Java】【高新技术】类加载器的高级问题分析
- sdoj 小鑫的城堡 并查集
- 005_005 Python 根据字符串中的数字排序,如f10应该在f2后面
- 【软件测试】神马是数据流覆盖