How to call Javascript __doPostBack from JSOUP

I have a website that calls __doPostBack for a specific link. I tried to load the page to which the link is being loaded, but manually enter the POST data, as well as manually set __EVENTTARGET and __EVENTARGUMENT, but I continue to receive the error page. If someone used the JSOUP library and found a workaround for this problem, please let me know. Here is the code to call the website with POST data:

Connection.Response res = Jsoup.connect("https://parentaccess.ocps.net/Progress/ProgressSummary.aspx?T=2").data(target.substring(0,target.length()-5)+"txtClass_DBID",dBID).data("__LASTFOCUS","").data("__EVENTVALIDATION", eventValidation).data("__VIEWSTATE", viewState).cookie("ASP.NET_SessionId", cookie).data("__EVENTTARGET",target).data("DropDownListGradingPeriod","3").data("__EVENTARGUMENT","").header("Content-Type","text/html; charset=utf-8").header("Connection", "keep-alive").header("Cache-Control", "private").method(Method.POST).execute();
                Document doc = res.parse();
                Document doc2 = Jsoup.connect("https://parentaccess.ocps.net/Progress/ProgressDetails.aspx").data(target.substring(0,target.length()-5)+"txtClass_DBID",dBID).data("__LASTFOCUS","").data("__EVENTVALIDATION", eventValidation).data("__VIEWSTATE", viewState).cookie("ASP.NET_SessionId", cookie).data("__EVENTTARGET",target).data("DropDownListGradingPeriod","3").data("__EVENTARGUMENT","").header("Content-Type","text/html; charset=utf-8").header("Connection", "keep-alive").header("Cache-Control", "private").get();

Please note that I tried both Connection.Response and JSOUP.connect with POST data, but got errors for doc2 (res loads the page, but the information should not be transmitted because a table with POST data is not created). Thanks!

+4
source share
2 answers

Use HTMLUNIT to handle javascript.

0
source

After spending a few days, the only solution I found was htmlunit.

Here is the working code:

HtmlPage page = webClient.getPage("PAGE_URL");
InputStream inputStream = 
page.getElementById({EL_ID}").click().getWebResponse().getContentAsStream();
OutputStream outputStream = new FileOutputStream(new File("FILE_NAME"));
IOUtils.copy(inputStream, outputStream);
0
source

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


All Articles