public GetRequestStream ( ) : System.IO.Stream | ||
return | System.IO.Stream |
using System; using System.IO; using System.Net; public class HttpWebRequestExample { public static void Main() { // Create a new web request HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.example.com/upload_data"); // Set the request method to POST request.Method = "POST"; // Set the request content type request.ContentType = "application/x-www-form-urlencoded"; // Convert the string data to a byte array byte[] data = System.Text.Encoding.UTF8.GetBytes("name=value"); // Get the request stream using (Stream stream = request.GetRequestStream()) { // Write the data to the request stream stream.Write(data, 0, data.Length); } // Get the response from the server using (WebResponse response = request.GetResponse()) { // Do something with the response } } }
using System; using System.IO; using System.Net; using System.Security.Cryptography.X509Certificates; public class HttpsWebRequestExample { public static void Main() { // Create a new web request HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.example.com/upload_data"); // Set the request method to POST request.Method = "POST"; // Set the request content type request.ContentType = "application/x-www-form-urlencoded"; // Add a client certificate to the request X509Certificate2 certificate = new X509Certificate2("client-cert.pfx", "password"); request.ClientCertificates.Add(certificate); // Convert the string data to a byte array byte[] data = System.Text.Encoding.UTF8.GetBytes("name=value"); // Get the request stream using (Stream stream = request.GetRequestStream()) { // Write the data to the request stream stream.Write(data, 0, data.Length); } // Get the response from the server using (WebResponse response = request.GetResponse()) { // Do something with the response } } }Both of these examples use the System.Net package library.