Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1.  public String loginForm() {
  2.  
  3.         String cookie1 = null;
  4.  
  5.         List<NameValuePair> formParams = new ArrayList<>();
  6.         formParams.add(new BasicNameValuePair("username",Constants.USERNAME));
  7.         formParams.add(new BasicNameValuePair("password",Constants.PASSWORD));
  8.         UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, Consts.UTF_8);
  9.         HttpPost httppost = new HttpPost(Constants.LOGIN);
  10.         httppost.setEntity(entity);
  11.  
  12.  
  13.         CloseableHttpClient httpclient = HttpClients.createDefault();
  14.         HttpClientContext context = HttpClientContext.create();
  15.         CloseableHttpResponse response = null;
  16.         try {
  17.             response = httpclient.execute(new HttpGet("http://zamunda.net/bananas"), context);
  18.             CookieStore cookieStore = context.getCookieStore();
  19.             List<Cookie> cookies = cookieStore.getCookies();
  20.  
  21.             for (Cookie cookie : cookies) {
  22.                 if (cookie.getName().contains(Constants.COOKIE_NAME)) {
  23.                     cookie1 = cookie.toString();
  24.                 }
  25.             }
  26.  
  27.         }
  28.         catch (IOException e) {
  29.             e.printStackTrace();
  30.         }
  31.         finally {
  32.             try {
  33.                 response.close();
  34.             } catch (IOException e) {
  35.                 e.printStackTrace();
  36.             }
  37.         }
  38.         return cookie1;
  39.     }
  40.  
  41.     public void getMovieId() {
  42.  
  43.         CloseableHttpClient httpclient = HttpClients.createDefault();
  44.         HttpClientContext context = HttpClientContext.create();
  45.         CloseableHttpResponse response = null;
  46.  
  47.         try {
  48.             response = httpclient.execute(new HttpGet("http://zamunda.net/catalogs/movies"), context);
  49.             HttpEntity entity = response.getEntity();
  50.  
  51.             System.out.println(response);
  52.  
  53.             System.out.println(entity.getContent());
  54.  
  55.             if (entity != null) {
  56.  
  57.                 InputStream is = entity.getContent();
  58.                 BufferedReader br = new BufferedReader(new InputStreamReader(is));
  59.                 String str ="";
  60.                 while ((str = br.readLine()) != null){
  61.                     System.out.println(""+str);
  62.                 }
  63.             }
  64.  
  65.         }
  66.         catch (IOException e) {
  67.             e.printStackTrace();
  68.         }
  69.  
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement