34
A
回答
72
這個怎麼樣?
using System;
using System.IO;
using System.Net;
using System.Text;
namespace Examples.System.Net
{
public class WebRequestPostExample
{
public static void Main()
{
// 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();
}
}
}
它採取從MSDN:MSDN on WebRequest
相關問題
- 1. 如何使用WebClient從網頁獲取異步發佈數據?
- 2. 從網址獲取POST響應並打印頁面響應?
- 3. 如何發佈ajax並獲得響應?
- 4. 發佈請求並獲取響應robotframework
- 5. WebRequest在登錄頁面發佈數據
- 6. PHP發送數據到URL並獲得該網頁的響應
- 7. 發佈數據並在asp.net中獲取響應
- 8. Iframe從父頁獲取/發佈數據
- 9. 如何發佈跨域數據並使用php和jquery獲得響應
- 10. 使用Python從網頁獲取數據
- 11. 如何將數據發佈到服務器並獲取響應?意向?
- 12. 從網頁中獲取數據,並在Android應用
- 13. 如何使AJAX請求發佈JSON數據並處理響應
- 14. 將數據從js發送到servlet並獲取響應
- 15. 從網頁獲取數據
- 16. 從網頁獲取數據
- 17. 從網頁獲取數據?
- 18. 如何發佈JSON,但使用Retrofit2獲取XML響應?
- 19. 從網頁獲取數據並在Android上使用Java
- 20. 如何發佈數據並從PHP的操作頁面獲取結果?
- 21. 如何使用asp.net網頁從Plesk10獲取數據
- 22. c#Webrequest Web響應獲取403:禁止
- 23. 如何從ajax發佈請求獲取響應頭
- 24. jQuery:從ajax響應發佈數據
- 25. 如何使用webrequest和響應登錄https網站
- 26. 發佈數據並獲得SOAP客戶端的響應
- 27. 獲取網絡服務響應數據
- 28. 從extjs網格獲取發佈參數
- 29. 從.aspx觸發數據響應頁
- 30. 如何獲取發送API請求並獲取Json響應c#