Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- import java.util.Random;
- import javax.net.ssl.*;
- public class Network {
- //Anfang Atribute
- private String user = "";
- private String pass = "";
- private String auth_url = "https://www.die-staemme.de/page/auth";
- private String ds = "www.die-staemme.de";
- private URL url;
- private String lastCSRFToken = "";
- //Ende Atribute
- //Anfang Operationen
- public Network() {
- }
- //Ende Operationen
- public void setUser(String pUser) {
- user = pUser;
- }
- public void setPass(String pPass) {
- pass = pPass;
- }
- private String getContentLenght() {
- int i = 30 + user.length() + pass.length();
- return Integer.toString(i);
- }
- private void setLastCSRFToken(String pToken) {
- lastCSRFToken = pToken;
- }
- private String getRandomCSRFToken() {
- Random rand = new Random();
- String s = "";
- int nextHexad;
- for (int i = 0; i < 6; i++) {
- nextHexad = rand.nextInt();
- s += Integer.toHexString(nextHexad);
- rand.setSeed(rand.nextLong()-rand.nextInt());
- }
- setLastCSRFToken(s);
- return s;
- }
- private byte[] getAuthParams() {
- String s = "username="+user+"&password="+pass+"&remember=1";
- try {
- return s.getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return "error".getBytes();
- }
- }
- public void auth() {
- try {
- url = new URL(auth_url);
- HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
- con.setRequestMethod("POST");
- con.setRequestProperty("Host", ds);
- con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");
- con.setRequestProperty("Accept", "application/json, text/javascript, */*; q=0.01");
- con.setRequestProperty("Accept-Language", "de-DE,de;q=0.9");
- con.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
- con.setRequestProperty("Referer", "https://"+ds+"/");
- con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- con.setRequestProperty("X-CSRF-Token", getRandomCSRFToken());
- con.setRequestProperty("X-Requested-With", "XMLHttpRequest");
- con.setRequestProperty("Content-Length", getContentLenght());
- con.setRequestProperty("Connection", "keep-alive");
- con.setDoOutput(true);
- con.setDoInput(true);
- //writing the params with outputstream, outputstreamwriter & bufferedwriter
- // con.getOutputStream().write(getAuthParams());
- // con.getOutputStream().flush();
- BufferedReader bR = new BufferedReader( new InputStreamReader(con.getInputStream()));
- do {
- System.out.println(bR.readLine());
- } while (bR.ready());
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement