如何打開網頁瀏覽器並在.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。謝謝
如何打開網頁瀏覽器並在.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。謝謝
如果你想要做的POST幕後的(即沒有進行瀏覽器顯示窗口/控件),這些鏈接可以幫助:
要張貼這樣的的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();
目前還不清楚你想達到什麼目的。你在談論webforms(客戶端或服務器端?),WPF或winforms? – Oded 2010-10-16 14:32:41
我想打開使用winforms發送郵件的網址。 – 2010-10-16 14:35:44
請在這種情況下用winforms標記你的問題,這樣你會得到相關的答案,更多的人看着它。 – Oded 2010-10-16 14:38:42