Asp.NET login using HTTP post method using jsoup

I recently tried to develop an Android application for my school friends, so they don’t need to use a web browser, but a simple application to check their updated grades and exam schedule, but since the school does not give permission to use their DB, the only method is to handle HTML parsing. so I found this Jsoup library and example and started writing my own code, but it always brings me the source of the login page to the page (it is not logged in at all)

public Document getHTMLsoure() { Document doc=null; try { doc = Jsoup.connect("http://karinca.meliksah.edu.tr") .data("ctl00$ContentPlaceHolder1$txtKullaniciAdi","usernm") .data("ctl00$ContentPlaceHolder1$txtSifre", "passwd") .data("ctl00$ContentPlaceHolder1$btnLogin", "Giriş") .userAgent("Mozilla") .post(); } catch (IOException e1) { e1.printStackTrace(); } 

return doc; }

-1
source share
1 answer

Please, check him. Result of Kullanıcı adı yada şifre hatası !

 Response res = Jsoup .connect("https://karinca.meliksah.edu.tr/View/Login") .userAgent("Mozilla") .execute(); Document doc = res.parse(); String eventArgument = doc.select("input[name=__EVENTARGUMENT]").val(); String viewState = doc.select("input[name=__VIEWSTATE]").val(); String viewStateGenerator = doc.select("input[name=__VIEWSTATEGENERATOR]").val(); String eventValidation = doc.select("input[name=__EVENTVALIDATION]").val(); String asyncPost = "true"; String ct = ""; String body = doc.body().html(); int indexOf = body.indexOf("Sys.WebForms.PageRequestManager._initialize(");; if(indexOf > -1){ int indexEnd = body.substring(indexOf).indexOf("');"); if(indexEnd > -1){ String temp = body.substring(indexOf, indexOf+indexEnd); int indexStart = temp.lastIndexOf("'"); ct = temp.substring(indexStart+1,temp.length()); } } Document doc1 = Jsoup.connect("https://karinca.meliksah.edu.tr/View/Login.aspx") .referrer("https://karinca.meliksah.edu.tr/View/Login") .cookies(res.cookies()) .data(ct+"$ContentPlaceHolder1$ScriptManager2",ct+"$ContentPlaceHolder1$UpdatePanel1|"+ct+"$ContentPlaceHolder1$btnLogin") .data(ct+"$ContentPlaceHolder1$txtKullaniciAdi","usernm") .data(ct+"$ContentPlaceHolder1$txtSifre", "passwd") .data("__EVENTTARGET",ct+"$ContentPlaceHolder1$btnLogin") .data("__EVENTARGUMENT",eventArgument) .data("__VIEWSTATE",viewState) .data("__VIEWSTATEGENERATOR",viewStateGenerator) .data("__EVENTVALIDATION",eventValidation) .data("__ASYNCPOST",asyncPost) .userAgent("Mozilla") .post(); System.out.println(doc1.html()); 
+3
source

Source: https://habr.com/ru/post/1270568/


All Articles