first part of auto results
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package de.jeyp91.tippligaforum;
|
||||
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.BasicCookieStore;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.*;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class TippligaWebsiteConnector {
|
||||
CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
|
||||
|
||||
CookieStore cookieStore = cm.getCookieStore();
|
||||
private static final Logger logger = LogManager.getLogger(TippligaWebsiteConnector.class);
|
||||
private final HttpClient client;
|
||||
|
||||
public TippligaWebsiteConnector() throws IOException {
|
||||
CookieHandler.setDefault(cm);
|
||||
|
||||
client = HttpClient.newBuilder()
|
||||
.cookieHandler(CookieHandler.getDefault())
|
||||
.connectTimeout(Duration.ofSeconds(10))
|
||||
.build();
|
||||
login();
|
||||
}
|
||||
|
||||
private void login() throws IOException {
|
||||
HttpRequest firstReq = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://tippliga-wuerzburg.de/ucp.php?mode=login"))
|
||||
.GET().build();
|
||||
|
||||
String firstReqBody = "";
|
||||
try {
|
||||
firstReqBody = client.send(firstReq, HttpResponse.BodyHandlers.ofString()).body();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<HttpCookie> firstReqCookieList = cookieStore.getCookies();
|
||||
|
||||
Pattern pattern = Pattern.compile("^[\\s\\S]*<input type=\"hidden\" name=\"creation_time\" value=\"([\\d]{10})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"form_token\" value=\"([\\d\\w]{40})\" \\/>[\\s\\S]*<input type=\"hidden\" name=\"sid\" value=\"([\\d\\w]{32})\" \\/>[\\s\\S]*$");
|
||||
Matcher matcher = pattern.matcher(firstReqBody);
|
||||
matcher.find();
|
||||
String creationTime = matcher.group(1);
|
||||
String formToken = matcher.group(2);
|
||||
String sid = matcher.group(3);
|
||||
|
||||
List<NameValuePair> urlParameters = new ArrayList<>();
|
||||
urlParameters.add(new BasicNameValuePair("username", "Julian"));
|
||||
urlParameters.add(new BasicNameValuePair("password", "original"));
|
||||
urlParameters.add(new BasicNameValuePair("creation_time", creationTime));
|
||||
urlParameters.add(new BasicNameValuePair("form_token", formToken));
|
||||
urlParameters.add(new BasicNameValuePair("sid", sid));
|
||||
urlParameters.add(new BasicNameValuePair("login", "Anmelden"));
|
||||
|
||||
HttpPost loginReq = new HttpPost("https://tippliga-wuerzburg.de/ucp.php?mode=login");
|
||||
try {
|
||||
loginReq.setEntity(new UrlEncodedFormEntity(urlParameters));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String form = new String(loginReq.getEntity().getContent().readAllBytes());
|
||||
String loginReqBody = "";
|
||||
try {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = httpClient.execute(loginReq);
|
||||
loginReqBody = EntityUtils.toString(response.getEntity());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
List<HttpCookie> loginReqCookieList = cookieStore.getCookies();
|
||||
logger.info(loginReqBody);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package de.jeyp91.tippligaforum;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TippligaWebsiteConnectorTest {
|
||||
@Test
|
||||
public void getChecksumOfPostTest() throws IOException {
|
||||
TippligaWebsiteConnector con = new TippligaWebsiteConnector();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user