[英]HTTP Requests in C#
I need to visit a URL, find a specific text box in said page - fill it with data and then submit a form. 我需要访问一个URL,在所述页面中找到一个特定的文本框 - 用数据填充它,然后提交一个表单。
How can I accomplish this in C#? 我怎样才能在C#中实现这一目标?
PS Innocent intentions. PS无辜的意图。
You'd be best looking at the WebRequest
class (System.Net). 你最好看一下WebRequest
类(System.Net)。
You'll want to look at the POST Method to post a form (click the submit button with the required fields completed). 您需要查看POST方法以发布表单(单击提交按钮并填写必填字段)。
Example: 例:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
There is a nice tutorial and lots of information on MSDN here . 有一个很好的教程和大量的信息在MSDN上这里 。 (Continuation of above source code) (上述源代码的延续)
if you visit the page in a browser and do the stuff you need manually with fiddler2 installed and activated you can see which requests get sent to the webserver. 如果您在浏览器中访问该页面并在安装并激活fiddler2的情况下手动完成所需的操作,您可以看到哪些请求被发送到Web服务器。
All you need to do is to replicate those requests (form posts) using for example the WebRequest class or the WebClient class in the .net framework. 您需要做的就是使用例如.net框架中的WebRequest类或WebClient类来复制这些请求(表单帖子)。
WatiN is also an alternative. WatiN也是另一种选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.