2010-10-16 77 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