从.NET应用程序POST一个表单

我不熟悉http的东西,但我怎样才能将数据提交到网站? 有一个提交按钮,我想从控制台应用程序“按下”。 这不是我自己的网站。

这是页面源的一部分,不确定它是否具有任何相关性:

我查看了HttpWebRequest类,但我不熟悉需要填写的属性。

对不起我很模糊,但我不熟悉http。

这是MSDN的ac / p。

  // 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); // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream (); // Write the data to the request stream. dataStream.Write (byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close (); // Get the response. WebResponse response = request.GetResponse (); // Display the status. Console.WriteLine (((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream (); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader (dataStream); // Read the content. string responseFromServer = reader.ReadToEnd (); // Display the content. Console.WriteLine (responseFromServer); // Clean up the streams. reader.Close (); dataStream.Close (); response.Close (); 

链接到页面

这个过程非常简单,但您需要首先弄清楚您需要发送什么以及可能需要的任何其他特殊编码/ cookie /等等。 我建议您使用Fiddler和/或Firebug for Firefox。 您可以通过网页查看工作请求中发生的所有事情,然后您可以在应用中模仿相同的行为。

你可以简单地看看codeproject HttpWebRequest / Response – 第1部分

这里有一个灵活且易于使用的示例: C#文件上传,包含表单字段,cookie和标题

 Response.Write("hello!"); Response.End();