0

I need to get and process some files published monthly on a website, this is how the HTML anchor is set on the website:

<a id="gv_data_btn_file_6" href="javascript:__doPostBack('gv_data$ctl08$btn_file','')">ListOfAutoCodes2018.zip</a>

After I click that this is the repose:

Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/octet-stream
Expires: -1
Server: Microsoft-IIS/8.5
content-disposition: attachment;filename=ListOfAutoCodes2018.zip
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 10 Sep 2018 18:37:26 GMT
Content-Length: 495042

Can you share a code or suggest how can I "simulate" the click and/or execution of the javascript funcion and then get response, which in this case is a CSV file into a stream?

Crowcoder
  • 11,250
  • 3
  • 36
  • 45
paburgos
  • 259
  • 2
  • 14
  • 1
    https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.htmlelement.invokemember?view=netframework-4.7.2#System_Windows_Forms_HtmlElement_InvokeMember_System_String_ – Steve Sep 10 '18 at 19:38
  • 1
    Use Fiddler, or some other program to capture the HTML Form that is POSTed when you click that button. You can then use a `WebClient` instance to reconstruct the form data, manually POST it (with whatever modification you need), and capture the results. – Bradley Uffner Sep 10 '18 at 19:51
  • 1
    https://stackoverflow.com/q/2425043/20126 – Amr Elgarhy Sep 10 '18 at 20:30
  • thanks for the answers now I see how it works, thanks! – paburgos Sep 10 '18 at 22:34

1 Answers1

0

I have called a c# button submit from C# code call from code like this:

// in C# code somewhere
btnSubmit_Click(Submit, null);  // where Submit, references the button on the HTML page

For a submit button declared like this on the HTML:

<asp:Button ID="Submit" Text="Submit" runat = "server" onClick="btnSubmit_Click" />

So if this is your application you may be able to recreate the call in C# like this using how I did it in my logic above:

btnSubmit_Click(gv_data_btn_file_6, null);
Brad
  • 3,454
  • 3
  • 27
  • 50
  • I don't think the website he needs to click on is one under his control. This will only work for websites that you can modify the source code for. – Bradley Uffner Sep 10 '18 at 19:48
  • yes as @BradleyUffner says the website is not under my control. thanks though! – paburgos Sep 10 '18 at 22:33