Microsoft Learn

HttpRequestMessage Class

Represents an HTTP request message.

Namespace:

System.Net.Http

Assembly:

System.Net.Http.dll

Syntax

public class HttpRequestMessage : IDisposable

Constructors

Name Description
HttpRequestMessage() Initializes a new instance of the HttpRequestMessage class.
HttpRequestMessage(HttpMethod, String) Initializes a new instance of the HttpRequestMessage class with a specific HTTP method and URI.
HttpRequestMessage(HttpMethod, Uri) Initializes a new instance of the HttpRequestMessage class with a specific HTTP method and URI.

Properties

Name Description
Content Gets or sets the HTTP content, if the request is not for a resource that is expected to have entity-body content.
Headers Gets an HttpRequestHeaders object that contains the HTTP headers for the current request.
Method Gets or sets the HTTP method used to send the request.
Options Gets the collection of optional properties for the request.
Properties Gets the collection of optional properties for the request.
RequestUri Gets or sets the Uniform Resource Identifier (URI) of the request.
Version Gets or sets the HTTP version used to send the request.

Methods

Name Description
Dispose() Releases the unmanaged resources that are used by the current instance of the HttpRequestMessage class.
Dispose(Boolean) Releases the unmanaged resources used by the current instance of the HttpRequestMessage class, and optionally releases the managed resources.
ToString() Returns a string that represents the current object.

Constructors

HttpRequestMessage()

Initializes a new instance of the HttpRequestMessage class.

public HttpRequestMessage()

HttpRequestMessage(HttpMethod, String)

Initializes a new instance of the HttpRequestMessage class with a specific HTTP method and URI.

public HttpRequestMessage( HttpMethod method, string requestUri )

Parameters:

  • method: The HTTP method to use.
  • requestUri: The URI to send the request to.

HttpRequestMessage(HttpMethod, Uri)

Initializes a new instance of the HttpRequestMessage class with a specific HTTP method and URI.

public HttpRequestMessage( HttpMethod method, Uri requestUri )

Parameters:

  • method: The HTTP method to use.
  • requestUri: The URI to send the request to.

Properties

Content

Gets or sets the HTTP content, if the request is not for a resource that is expected to have entity-body content.

public HttpContent Content { get; set; }

A HttpContent object that contains the HTTP body of the request. null if the request has no body.

Headers

Gets an HttpRequestHeaders object that contains the HTTP headers for the current request.

public HttpRequestHeaders Headers { get; }

An HttpRequestHeaders object that contains the HTTP headers for the current request.

Method

Gets or sets the HTTP method used to send the request.

public HttpMethod Method { get; set; }

An HttpMethod object representing the HTTP method.

Options

Gets the collection of optional properties for the request.

public ICollection<KeyValuePair<string, object>> Options { get; }

A collection of optional properties for the request.

Properties

Gets the collection of optional properties for the request.

public IDictionary<string, object> Properties { get; }

A dictionary of optional properties for the request.

RequestUri

Gets or sets the Uniform Resource Identifier (URI) of the request.

public Uri RequestUri { get; set; }

A Uri object representing the URI of the request.

Version

Gets or sets the HTTP version used to send the request.

public Version Version { get; set; }

A Version object representing the HTTP version.

Methods

Dispose()

Releases the unmanaged resources that are used by the current instance of the HttpRequestMessage class.

public void Dispose()

This method is called by the public Dispose method to release unmanaged resources.

Dispose(Boolean)

Releases the unmanaged resources used by the current instance of the HttpRequestMessage class, and optionally releases the managed resources.

protected virtual void Dispose( bool disposing )

Parameters:

  • disposing: true to release both managed and unmanaged resources; false to release only unmanaged resources.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns a string that represents the current object.