public EndGetRequestStream ( IAsyncResult asyncResult ) : Stream | ||
asyncResult | IAsyncResult | |
return | Stream |
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://example.com"); request.Method = "POST"; request.ContentType = "application/json"; request.BeginGetRequestStream((asyncResult) => { // Write some data to the request stream using (var writer = new StreamWriter(request.EndGetRequestStream(asyncResult))) { writer.Write("{\"name\": \"John\", \"age\": 30}"); } // Make the HTTP request request.BeginGetResponse((responseAsyncResult) => { // Handle the HTTP response var response = (HttpWebResponse)request.EndGetResponse(responseAsyncResult); Console.WriteLine(response.StatusCode); }, null); }, null);
var request = (HttpWebRequest)WebRequest.Create("https://example.com"); request.Method = "GET"; var responseTask = Task.Factory.FromAsyncThis example creates an HTTP GET request and uses the Task.Factory.FromAsync method to asynchronously make the HTTP request. The EndGetResponse method is called as the callback function to complete the asynchronous request and get the response object. The await keyword is used to wait for the asynchronous task to complete. This example uses the System.Net.Http package library.( request.BeginGetResponse, request.EndGetResponse, null); var response = await responseTask; Console.WriteLine(response.ContentType);
public EndGetRequestStream ( IAsyncResult asyncResult ) : Stream | ||
asyncResult | IAsyncResult | |
return | Stream |