I had the same problem (different site) but the question wasn t actually answered.
So PHP and Curl lib (and yes this is a PHP question), posting a VIEWSTATE on an ASP website.
Please, if you have no idea what this is about, do not post.
Here is the code I have so far:
(I am trying to get the excel file).
#! /usr/local/bin/php -q
<?php
$url="https://elicensing.iowaabd.com/OnDemandReport.aspx";
$referer="https://elicensing.iowaabd.com";
$header[] = "Content-Type: text/html; charset=utf-8";
$cookie="cookie.txt";
$fp=fopen($cookie,w);
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_REFERER,$referer);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$content=curl_exec($ch);
$array=explode("\n",$content);
$count=count($array);
for($i=0;$i<$count;$i++){
if(stristr($array[$i],"VIEWSTATE")){
$array1=explode('value="',$array[$i]);
$content1=$array1[1];
$array2=explode('"',$content1);
$content2=$array2[0];
$VIEWSTATE=$content2;
}
if(stristr($array[$i],"EVENTVALIDATION")){
$array1=explode('value="',$array[$i]);
$content1=$array1[1];
$array2=explode('"',$content1);
$content2=$array2[0];
$EVENTVALIDATION=$content2;
}
}
//echo $VIEWSTATE."\n";
$VIEWSTATE=urlencode($VIEWSTATE);
$fields = "EVENTVALIDATION=$EVENTVALIDATION&EVENTTARGET=lnkExcelExport&EVENTARGUMENT=&VIEWSTATE=$VIEWSTATE";
$url="https://elicensing.iowaabd.com/OnDemandReport.aspx";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
//
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_REFERER,$referer);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//
$content_stage2=curl_exec($ch);
unlink ("result.txt");
$handle = fopen ("result.txt",w);
fwrite ($handle,$content_stage2);
?>