Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String loginForm() {
- String cookie1 = null;
- List<NameValuePair> formParams = new ArrayList<>();
- formParams.add(new BasicNameValuePair("username",Constants.USERNAME));
- formParams.add(new BasicNameValuePair("password",Constants.PASSWORD));
- UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, Consts.UTF_8);
- HttpPost httppost = new HttpPost(Constants.LOGIN);
- httppost.setEntity(entity);
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpClientContext context = HttpClientContext.create();
- CloseableHttpResponse response = null;
- try {
- response = httpclient.execute(new HttpGet("http://zamunda.net/bananas"), context);
- CookieStore cookieStore = context.getCookieStore();
- List<Cookie> cookies = cookieStore.getCookies();
- for (Cookie cookie : cookies) {
- if (cookie.getName().contains(Constants.COOKIE_NAME)) {
- cookie1 = cookie.toString();
- }
- }
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- finally {
- try {
- response.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return cookie1;
- }
- public void getMovieId() {
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpClientContext context = HttpClientContext.create();
- CloseableHttpResponse response = null;
- try {
- response = httpclient.execute(new HttpGet("http://zamunda.net/catalogs/movies"), context);
- HttpEntity entity = response.getEntity();
- System.out.println(response);
- System.out.println(entity.getContent());
- if (entity != null) {
- InputStream is = entity.getContent();
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
- String str ="";
- while ((str = br.readLine()) != null){
- System.out.println(""+str);
- }
- }
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement