I am trying to detect redirected
page on android webview
. After alot of effort , I found that status code for redirected page lies in between 300 and 400. I also checked status code for redirected page "en.m.wikipedia.com/wiki/Automobile" and got the desired result.
But I am trying to replicate samething in Android webview.I don't get 30X but get 200.
Here is my code:
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;
}
}
}
Here is my output:
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
Thanks in Advance.