Вы можете получить его, нажав на веб-адрес через 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);
EDIT:
Вы можете получить печенье из WebView как:
@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 для доступа, что страница – Scit
Смотрите мой отредактированный ответ –
и как использовать это печенье на OkHttpClient (или любой другой клиент)? Сайт, на котором я хочу получить HTML на странице, доступ к которой возможен только в том случае, если у меня есть логин (я уже вхожу в систему в WebView) – Scit