我正在尝试检测redirected
android 上的页面webview
。经过一番努力,我发现重定向页面的状态码在 300 到 400 之间。我还检查了重定向页面“en.m.wikipedia.com/wiki/Automobile”的状态码并得到了想要的结果。但我试图在 Android webview 中复制同样的东西。我没有得到 30 倍,而是得到了 200 倍。
这是我的代码:
public class MyActivity extends Activity {
private WebView webView;
private myWebChromeClient mWebChromeClient;
private myWebViewClient mWebViewClient;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webView);
mWebViewClient = new myWebViewClient();
webView.setWebViewClient(mWebViewClient);
// mWebChromeClient = new myWebChromeClient();
// webView.setWebChromeClient(mWebChromeClient);
webView.getSettings().setJavaScriptEnabled(true);
String url ="http://en.wikipedia.com/wiki/Automobile";
webView.loadUrl(url);
}
class myWebViewClient extends WebViewClient {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.v("url loaded "," "+url);
try{
HttpClient httpClient;
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
httpClient = new DefaultHttpClient(params);
HttpPost post = new HttpPost(url);
HttpResponse response = httpClient.execute(post);
Log.w("Response ","Status line : "+ response.getStatusLine().toString());
}catch(Exception e){
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
}
}
这是我的输出:
V/ url loaded: http://en.wikipedia.com/wiki/Automobile
W/Response: Status line : HTTP/1.0 200 OK
url loaded: http://en.wikipedia.org/wiki/Automobile
Response: Status line : HTTP/1.0 200 OK
url loaded: http://en.m.wikipedia.org/wiki/Automobile
Response: Status line : HTTP/1.1 200 OK
提前致谢。