How is it possible to login programmatically on to a website ?
Example: The User type in his login data in EditText and click on the login Button. Then opens a WebView, where he is logged in.
I tried to work with these code examples but:
How to connect via HTTPS using Jsoup? - i got Errors
How to log in to an HTTPS website with Jsoup? - i didnt got Errors but i cant login
Jsoup HTTPS connecting - it dont work i got Errors
After i used this, i tried this
class JsoupAsyncIserv extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
//HTML Parsen
try {
Connection.Response login = Jsoup.connect("https://lmg-nhs.de/idesk")
.data("login_act", "MyUsername")
.data("login_pwd", "MyPW")
.method(Connection.Method.POST)
.execute();
Document document = Jsoup.connect("https://lmg-nhs.de/idesk")
.cookies(login.cookies())
.get();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
}
}
It works, but i cant login.
private class IServAsyncTask extends AsyncTask<Void, Void, Void>{
private String resp;
protected String doInBackground(String... params) {
Connection.Response res = null;
try {
res = Jsoup.connect("https://lmg-nhs.de")
.data("login_act", "myUsername")
.data("login_pwd", "myPW")
.data("submit", "Anmelden")
.method(Connection.Method.POST)
.execute();
} catch (IOException e) {
e.printStackTrace();
}
try {
Document doc = res.parse();
} catch (IOException e) {
e.printStackTrace();
}
String sessionId = res.cookie("PHPSESSID");
try {
Document doc2 = Jsoup.connect("https://lmg-nhs.de")
.cookie("PHPSESSID", sessionId)
.get();
} catch (IOException e) {
e.printStackTrace();
}
return resp;
}
@Override
protected Void doInBackground(Void... voids) {
return null;
}
}
If you can, try to explain it at an or my example, because beginners (like me) can easier learn it this way.