如何用c#应用程序填充外部Web表单? [英] how to fill an external web form with c# application?
问题描述
目前,当您请求url1时,您将被重定向到url2
(尽管在小提琴手中,我获得了200个状态 - 为什么?)
url1将可用 - 少数第一批填写网页并提交它的人可以以折扣价购买真正好的产品。
我想写ac#应用程序将尝试访问循环中的url1。
它将输入url1后,我希望它填写一个已知的提前表单并选择一些下拉列表并提交我的请求。
我已经开始:
static void Main(string [] args)
{
string url =https:/ / URL1\" ;
WebRequest请求= HttpWebRequest.Create(url);
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string urlText = reader.ReadToEnd();
}
但我不确定如何:
1.检查响应的URL(我想检查302,但是filddler显示200.我可以在这个 StreamReader阅读器中看到状态码
?)
-
考虑到这个表单的例子,我怎样才能自动填充它?
< td style =width:100px;>
*名字:
< / td>
< td>
< input name =ctl00 $ ctl00 $ Content $ Main $ OrderNameFirsttype =textid =Content_Main_OrderNameFirststyle =width:150px; />
< span id =Content_Main_RequiredFieldValidator9class =textValidatorstyle =display:none;>שדהחובה< / span>
< / td>
< td style =vertical-align:top; padding-right:100px;>
< / td>
< / tr>
< / td>
< / tr>
< tr>
< td>
*类型:
< / td>
< td colspan =2>
< option value =Visa> A< / option>
< option value =IsraCard> B< / option>
< option value =MasterCard> C< / option>
唯一可以做到这一点的方法是(使用Web浏览器控件进行自动填充)。 b
$ b
您可以使用 Web Response
和 Web请求
来获取响应以及何时它会收到正确的一个,你可以使用
WebBrowser1.Navigate(http://url.com);
从那里你可以使用一个古老的技巧将数据放入表单中。
这将不会更改当前页面的地址,但会在页面上执行此JavaScript。
它会找到类名为textbox的第一个元素并赋予其值'email@domain.com'。
WebBrowser1.Navigate(javascript:void(document.getElementsByClassName('textbox')[0] .value ='email@domain.com'));
提示:您可以使WebBrowser不可见。
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);
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.
这篇关于如何用c#应用程序填充外部Web表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!