您可以通过点击该网页的网址,通过DefaultHttpClient
为得到它:
HttpClient httpclient = new DefaultHttpClient(); // Create HTTP Client
HttpGet httpget = new HttpGet("http://yoururl.com"); // Set the action you want to do
HttpResponse response = httpclient.execute(httpget); // Executeit
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent(); // Create an InputStream with the response
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) // Read line by line
sb.append(line + "\n");
String resString = sb.toString(); // Result is here
is.close(); // Close the stream
你必须添加一些超时PARAMS还有:
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters,3000); // 3s max for connection
HttpConnectionParams.setSoTimeout(httpParameters, 4000); // 4s max to get data
HttpClient httpclient = new DefaultHttpClient(httpParameters);
编辑:
您可以从网页流量为获得饼干:
@Override
public void onPageFinished(WebView view, String url){
String cookies = CookieManager.getInstance().getCookie(url);
Log.d(TAG, "All the cookies in a string:" + cookies);
}
但我需要的WebView的cookie来访问该页面 – Scit
看到我的编辑答案 –
以及如何使用上OkHttpClient(或任何客户端)饼干吗?该网站我想在只有登录时才能访问的页面上获取HTML(我已经登录了WebView) – Scit