Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lovecoding.miit.API;
- import java.io.BufferedOutputStream;
- import java.io.BufferedWriter;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.net.HttpURLConnection;
- import java.net.URL;
- /**
- * Created by alex on 21.02.18.
- */
- public class RequestUtil {
- private final static int CONNECTION_TIMEOUTREAD=15000;
- private final static int CONNECTION_TIMEOUT=20000;
- public static int getAuth(String login, String password) {
- HttpURLConnection urlcon = null;
- OutputStream wr = null;
- int responseCode=-1;
- String query = "j_username=" + login + "&j_password=" + password + "&submit=%D0%92%D0%BE%D0%B9%D1%82%D0%B8";
- try {
- urlcon = (HttpURLConnection) new URL("https://my.miit.ru/cabinet/hello/j_security_check").openConnection();
- urlcon.setReadTimeout(CONNECTION_TIMEOUTREAD);
- urlcon.setConnectTimeout(CONNECTION_TIMEOUT);
- urlcon.setRequestMethod("POST");
- urlcon.setDoOutput(true);
- wr = urlcon.getOutputStream();
- BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(wr,"UTF-8"));
- bufferedWriter.write(query);
- bufferedWriter.flush();
- bufferedWriter.close();
- responseCode=urlcon.getResponseCode();
- } catch (IOException ioe) {
- } finally {
- try {
- if (urlcon != null) {
- urlcon.disconnect();
- }
- if (wr != null) {
- wr.close();
- }
- } catch (IOException ioe) {
- }
- }
- return responseCode;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement