Java – How to call a Javascript __doPostBack from JSOUP

How to call a Javascript __doPostBack from JSOUP… here is a solution to the problem.

How to call a Javascript __doPostBack from JSOUP

I have a website that calls __doPostBack for a specific link. I tried to load the page loaded by the link, but manually entered the POST data and manually set the __EVENTTARGET and __EVENTARGUMENT, but I kept getting the error page. If anyone uses the JSOUP library and finds a solution to this problem, please let me know. This is the code that calls 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();

Note that I’ve tried Connection.Response and JSOUP.connect with POST data, but keep getting the error doc2 (res will load the page, but can’t pass the information because the table given POST data isn’t generated). Thanks!

Solution

USE HTMLUNIT TO PROCESS JAVASCRIPT.

Related Problems and Solutions