public EndGetRequestStream ( System asyncResult ) : System.IO.Stream | ||
asyncResult | System | |
return | System.IO.Stream |
WebRequest request = WebRequest.Create("https://www.example.com"); request.Method = "POST"; request.BeginGetRequestStream((asyncResult) => { Stream requestStream = request.EndGetRequestStream(asyncResult); byte[] data = Encoding.UTF8.GetBytes("Hello World"); requestStream.Write(data, 0, data.Length); requestStream.Close(); }, null);
Uri uri = new Uri("https://www.example.com"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "POST"; request.ContentType = "application/json"; request.BeginGetRequestStream((asyncResult) => { Stream requestStream = request.EndGetRequestStream(asyncResult); string jsonData = "{ \"name\": \"John Doe\", \"age\": 25 }"; byte[] data = Encoding.UTF8.GetBytes(jsonData); requestStream.Write(data, 0, data.Length); requestStream.Close(); }, null);In this example, we create a POST request to "https://www.example.com" with a JSON payload and write the payload to the request stream using EndGetRequestStream method. We also set the Content-Type header to "application/json" using ContentType property. Package Library: This method is a part of the System.dll assembly which is included in the .NET Framework Class Library.
public EndGetRequestStream ( System asyncResult ) : System.IO.Stream | ||
asyncResult | System | |
return | System.IO.Stream |