[英]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.