我试图在webview中向服务器发布一些URL时获取响应标头。我正在使用shouldInterceptRequest方法。Android中的shouldInterceptRequest中的webview中获取响应标头
@Override
public WebResourceResponse shouldInterceptRequest(final WebView view, final WebResourceRequest request) {
if(request.getUrl().toString().contains(SMConstant.INTERCEPTED_URL)){
if(interceptFlag==0){
((Activity) mContext).runOnUiThread(new Runnable(){
@Override
public void run() {
view.postUrl(request.getUrl().toString(), EncodingUtils.getBytes(postData, "UTF-8"));
}
});
interceptFlag++;
}
}
return super.shouldInterceptRequest(view, request);
}
此方法返回WebResourceResponse对象。但是我没有得到如何从中获取响应头的方式。
默认情况下return super.shouldInterceptRequest(view, request);
返回null。
所以,应该做什么,以便实际的webview响应应该被捕获。
web视图并不响应头提供接入。如果您需要访问这些数据,您必须使用HTTP客户端并自行检索页面。 http://stackoverflow.com/questions/3134389/access-the-http-response-headers-in-a-webview –