0
我想在android webview
上檢測redirected
頁面。經過很多努力,我發現重定向頁面的狀態代碼在300到400之間。我還檢查了重定向頁面「en.m.wikipedia.com/wiki/Automobile」的狀態代碼,並獲得了期望的結果。 但我試圖複製samething Android中webview.I沒有得到30X,但得到200期望300到400之間的狀態代碼,但得到200 android httpclient
這裏是我的代碼:
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
提前致謝。
實現此,我得到的響應:V/URL加載:http://en.wikipedia.com/wiki/Automobile W /響應:狀態行:HTTP/1.0 301已移至永久 URL加載:HTTP ://en.wikipedia.org/wiki/Automobile 響應:狀態行:HTTP/1.0 200 OK 加載的URL:http://en.m.wikipedia.org/wiki/Automobile 響應:狀態行:HTTP/1.1 200 OK(仍未完成重定向)。 – vijay
http://en.m.wikipedia.org/wiki/Automobile返回200,不重定向。 – msh
我打開en.wikipedia.com/wiki/Automobile.And它被重定向到en.m.wikipedia.org/wiki/Automobile.Probably在服務器端,他們使用useragent.I需要知道所有重定向。如何我得到所有這些? – vijay