How do I handle __doPostBack() in Greasemonkey?
-
14-06-2021 - |
Question
There are a series of links handled by that function that contain what I need and I'm trying to use Greasemonkey to save the content inside those links.
Here's what I've tried:
var content;
var viewstate;
var crystalstate;
$(document).ready(function() {
viewstate = $("#__VIEWSTATE").val();
crystalstate = $("#__CRYSTALSTATEctl00$main$CrystalReportViewer1").val();
$.post("CautarePolite.aspx", {
__EVENTTARGET: 'ctl00$main$gvPolite$ctl02$lbDetaliiPolita',
__EVENTARGUMENT: '',
__CRYSTALSTATEctl00$main$CrystalReportViewer1: crystalstate,
__VIEWSTATE: viewstate
},
function( data ) {
content = data;
} );
alert('');
$.post("script_url.php", { data: content } );
});
This gives me a page with the following error message:
"Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster."
Here is a bit of the code on the page which may be of interest:
<form method="post" action="CautarePolite.aspx" id="aspnetForm" class="wrap">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__CRYSTALSTATEctl00$main$CrystalReportViewer1" id="long value*" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="*very long value*" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
Solution
It was missing __VIEWSTATEENCRYPTED
The input field was further down in the source code, but that solved it. I got what I needed.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow