[英]HTTP Requests in C#
我需要访问一个URL,在所述页面中找到一个特定的文本框 - 用数据填充它,然后提交一个表单。
我怎样才能在C#中实现这一目标?
PS无辜的意图。
你最好看一下WebRequest
类(System.Net)。
您需要查看POST方法以发布表单(单击提交按钮并填写必填字段)。
例:
// 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);
有一个很好的教程和大量的信息在MSDN上这里 。 (上述源代码的延续)
如果您在浏览器中访问该页面并在安装并激活fiddler2的情况下手动完成所需的操作,您可以看到哪些请求被发送到Web服务器。
您需要做的就是使用例如.net框架中的WebRequest类或WebClient类来复制这些请求(表单帖子)。
WatiN也是另一种选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.