how to fill an external web form with c# application?
There is some url (say url1) which is blocked till some unknown time. Currently, when you request for url1 you're redirected to url2 (Though in fiddler I get a 200 status - why ?)
When url1 will be available - the few first people who will fill the a web-fom and submit it can buy a really nice product in a disccounted price.
i want to write a c# application which will try to access url1 in a loop. After it will enter url1 I want it to fill a known in advance form and select some drop-down list and submit my request.
I have started with:
static void Main(string[] args)
{
string url = "https://url1";
WebRequest request = HttpWebRequest.Create(url);开发者_C百科
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string urlText = reader.ReadToEnd();
}
But I'm not sure how to:
1. check the response's url (I thought to check for 302, but filddler show 200. can I see status code in this StreamReader reader
?)
Given this form example, how can I fill it automatically ?
<td style="width: 100px;"> *First name: </td> <td> <input name="ctl00$ctl00$Content$Main$OrderNameFirst" type="text" id="Content_Main_OrderNameFirst" style="width:150px;" /> <span id="Content_Main_RequiredFieldValidator9" class="textValidator" style="display:none;">שדה חובה</span> </td> <td style="vertical-align: top; padding-right: 100px;"> <input type="image" name="ctl00$ctl00$Content$Main$ImageButton1" id="Content_Main_ImageButton1" class="image" src="Images/buttonSubmitPaypal.png" onclick="javascript: return SubmitPaypal(this);" style="cursor:pointer;" /> </td> </tr> </td> </tr> <tr> <td> *Type: </td> <td colspan="2"> <select name="ctl00$ctl00$Content$Main$OrderCreditType" id="Content_Main_OrderCreditType"> <option value="Visa">A</option> <option value="IsraCard">B</option> <option value="MasterCard">C</option>
The only way you can do this (Without invoking javascript which is insanely confusing) is to use a Web Browser control to do the auto fill.
You can use Web Response
and Web Request
to get the response and when it receives the correct one you can use
WebBrowser1.Navigate("http://url.com");
From there you can use a old trick to put data in to a form. This will not change the address of the current page but execute this javascript on page. It will find the first element with the class name of 'textbox' and give it a value of 'email@domain.com'
WebBrowser1.Navigate("javascript: void(document.getElementsByClassName('textbox')[0].value = 'email@domain.com')");
TIP: You can make the WebBrowser invisible.
精彩评论