2010-10-16 79 views
2

如何打开网页浏览器并在.net 2内发送POST打开网址发送POST

类似于这个html函数。

<form action="http:www.url.com/get" method="post"> 
    <input name="tt_2a" > 
    <input type="submit" value="submit"> 

我想要的东西喜欢我上面提到的HTML函数,打开一个URL,张贴一些东西,并在打开的页面中看到结果。我不需要web respose。谢谢

+0

目前还不清楚你想达到什么目的。你在谈论webforms(客户端或服务器端?),WPF或winforms? – Oded 2010-10-16 14:32:41

+0

我想打开使用winforms发送邮件的网址。 – 2010-10-16 14:35:44

+0

请在这种情况下用winforms标记你的问题,这样你会得到相关的答案,更多的人看着它。 – Oded 2010-10-16 14:38:42

回答

2

您可以在您的winforms应用程序中使用WebClient以使用网页。

有关使用WebClient发布表单数据的更多信息,请参阅thisthis问题。

4

要张贴这样的的WebRequest:

 // 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(); 

http://msdn.microsoft.com/en-us/library/debx8sh9.aspx