Guest User

Untitled

a guest
Nov 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1.     public String getUrl(String url) {
  2.         HttpClient httpclient = new DefaultHttpClient();
  3.         String html = "";
  4.         try {
  5.             CookieStore cookieStore = new BasicCookieStore();
  6.             HttpContext localContext = new BasicHttpContext();
  7.             localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
  8.  
  9.             HttpGet httpget = new HttpGet(url);
  10.  
  11.             // Pass local context as a parameter
  12.             HttpResponse response = httpclient.execute(httpget, localContext);
  13.  
  14.             InputStream in = response.getEntity().getContent();
  15.             BufferedReader reader = new BufferedReader(
  16.                     new InputStreamReader(in));
  17.             StringBuilder str = new StringBuilder();
  18.             String line = null;
  19.             while ((line = reader.readLine()) != null) {
  20.                 str.append(line);
  21.             }
  22.             in.close();
  23.             html = str.toString();
  24.  
  25.         } catch (ClientProtocolException e) {
  26.             // TODO Auto-generated catch block
  27.             e.printStackTrace();
  28.         } catch (IOException e) {
  29.             // TODO Auto-generated catch block
  30.             e.printStackTrace();
  31.         } finally {
  32.             httpclient.getConnectionManager().shutdown();
  33.             return html;
  34.         }
  35.     }
Add Comment
Please, Sign In to add comment