任何人都可以帮助我,我想在使用webView时从网址捕获响应。
webView = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings();
//webView.loadUrl(KEY_URL);
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
protected Void doInBackground(Void... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.abclogin.com/login");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
2);
nameValuePairs.add(new BasicNameValuePair("userName",
"YourUserName"));
nameValuePairs.add(new BasicNameValuePair("password",
"YourPassword"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String strResponse = "";
HttpEntity resEntity = response.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(
resEntity.getContent(), "UTF-8"));
String line;
while (((line = br.readLine()) != null)) {
strResponse = strResponse + line + " ";
}
// Now you can process the response to either see
// if it was successful or do whatever you want to
// with the results of the post
Log.v("result" , strResponse);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
例如: www.abclogin.com/login.php?username=abc&password=abc
所以我在Android应用程序中想要的是 log.v( “响应”,响应);
和 username = abc 密码= abc
实际上,当我点击webview网址上的登录按钮时,我填充的字段可以通过我的Android应用程序捕获