Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String getUrl(String url) {
- HttpClient httpclient = new DefaultHttpClient();
- String html = "";
- try {
- CookieStore cookieStore = new BasicCookieStore();
- HttpContext localContext = new BasicHttpContext();
- localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
- HttpGet httpget = new HttpGet(url);
- // Pass local context as a parameter
- HttpResponse response = httpclient.execute(httpget, localContext);
- InputStream in = response.getEntity().getContent();
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(in));
- StringBuilder str = new StringBuilder();
- String line = null;
- while ((line = reader.readLine()) != null) {
- str.append(line);
- }
- in.close();
- html = str.toString();
- } catch (ClientProtocolException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- httpclient.getConnectionManager().shutdown();
- return html;
- }
- }
Add Comment
Please, Sign In to add comment