lundi 22 août 2016

C# Web Form Submission with WebClient Example

I have spent several days trying to figure this out... I've read all the relevant posts on Stack Overflow and have not found something that works although I'm a novice in the web request/response programming world..

Problem: I have an existing application that captures data off of a web page. Simple webclient downloads page (webclient.downloadstring(url)) that parses the html and grabs relevant data... Works great. Now, I have to grab additional data off this site, but the page that has the data is a list of information that has ASP.NET javascript postbacks that are form submits.

<a id="ctl00_ContentPlaceHolder1_GridViewSort_ctl02_LinkButton1" class="ui-btn ui-mini center noprint" href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$GridViewSort$ctl02$LinkButton1&#39;,&#39;&#39;)">More Info</a>

I have captured all the relevant input values from the initial web request form using developer tools:

__EVENTARGUMENT: 
   __EVENTTARGET: ctl00%24ContentPlaceHolder1%24GridViewSort%24ctl03%24LinkButton1
   __EVENTVALIDATION: tpO...
   __VIEWSTATE: bI2vX...
   __VIEWSTATEENCRYPTED: 
   __VIEWSTATEGENERATOR: 5037098B
   ctl00%24ContentPlaceHolder1%24hfTicket: 0
   ctl00%24ucheader2%24m_textBoxSearch: Search%E2%80%A6

and have tried to mimic the postback using WebClient.UploadData(url, data) where data is converted to ascii array of byte[] as per other examples. I have also tried to capture headers and cookies, but this is where things start to fall apart... Examples I have found are not working for me.

Has anyone who has accomplished this please provide a code example that I can start with... I have also downloaded and tried WatIn... this may work as a temporary solution, but browser availability limitations will require far too much maintenance and intervention... I really would like to figure out how to do this with a .NET solution. Moving forward, I can see this as being a necessity.

Thank you in advance...




Aucun commentaire:

Enregistrer un commentaire