我有这条WebView代码,应该登录网站,然后加载该网站的某个页面。
webView = (WebView) findViewById(R.id.recording_web_view);
Bundle b = getIntent().getExtras();
String filename = b.getString("filename");
SettingsManager setman = SettingsManager.getInstance(getBaseContext());
//Login to webinterface before we can watch the recording
String postData = "username=" + setman.getUserName() + "&password=" + setman.getPassword();
//This is the section of code that fixes redirects to external apps
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
return false;
}
});
//Post login to get session
webView.postUrl("http://" + setman.getIp() + "/login", EncodingUtils.getBytes(postData, "BASE64"));
//Load actual recording
webView.loadUrl("http://" + setman.getIp() + "/movies/" + filename);
当我运行这个时,我只得到登录页面,服务器说它没有收到postdata。但是,当我删除loadUrl行时,它会收到登录数据并在登录后加载页面。
谁能告诉我我做错了什么?感谢
答案 0 :(得分:1)
尝试在WebViewClient中使用:
@Override
public void onPageFinished( WebView view, String url)
{
view.loadUrl( "http://" + setman.getIp() + "/movies/" + filename);
}
您也可以查看请求错误:
@Override
public void onReceivedError( WebView view, int errorCode, String description, String failingUrl)
答案 1 :(得分:0)
启用JavaScript
webView.getSettings().setJavaScriptEnabled(
true);