HttpRequestMessage
HttpRequestMessage
HttpRequestMessage
HttpRequestMessage
Class
Definition
Represents an HTTP request message including headers.
public : sealed class HttpRequestMessage : IClosable, IStringable, IHttpRequestMessagepublic sealed class HttpRequestMessage : IDisposable, IStringable, IHttpRequestMessagePublic NotInheritable Class HttpRequestMessage Implements IDisposable, IStringable, IHttpRequestMessage// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Remarks
The HttpRequestMessage class contains headers, the HTTP verb, and potentially data. This class is commonly used by developers who need additional control over HTTP requests. Common examples include the following:
- To examine the underlying SSL/TLS transport information.
- To use a less-common HTTP method.
- To explicitly set request properties on the HttpRequestMessage.
In these cases, an app uses one of the HttpRequestMessage constructors to create an HttpRequestMessage instance. The app sets various properties on the HttpRequestMessage as needed. Then the HttpRequestMessage is passed as a parameter to one of the HttpClient.SendRequestAsync methods.
A number of convenience methods on the HttpClient class automatically create an HttpRequestMessage object for the app. These methods include the following:
- DeleteAsync.
- The GetAsync methods.
- GetBufferAsync.
- GetInputStreamAsync.
- GetStringAsync.
- PostAsync.
- PutAsync.
Any filters that you add to the filter pipeline will be passed the HttpRequestMessage object whether it was explicitly specified by the app or was automatically constructed for you.
Constructors
HttpRequestMessage() HttpRequestMessage() HttpRequestMessage() HttpRequestMessage()
Initializes a new instance of the HttpRequestMessage class.
public : HttpRequestMessage()public HttpRequestMessage()Public Sub New()// You can use this method in JavaScript.
- See Also
HttpRequestMessage(HttpMethod, Uri) HttpRequestMessage(HttpMethod, Uri) HttpRequestMessage(HttpMethod, Uri) HttpRequestMessage(HttpMethod, Uri)
Initializes a new instance of the HttpRequestMessage class with an HTTP method and a request Uri.
public : HttpRequestMessage(HttpMethod method, Uri uri)public HttpRequestMessage(HttpMethod method, Uri uri)Public Sub New(method As HttpMethod, uri As Uri)// You can use this method in JavaScript.
- method
- HttpMethod HttpMethod HttpMethod HttpMethod
The HTTP method to perform
Properties
Content Content Content Content
Gets or sets the HTTP content to send to the server on the HttpRequestMessage object.
public : IHttpContent Content { get; set; }public IHttpContent Content { get; set; }Public ReadWrite Property Content As IHttpContent// You can use this property in JavaScript.
The HTTP content to send to the server on the HttpRequestMessage object.
Remarks
The content of an HTTP request message corresponds to the entity body defined in RFC 2616.
A number of classes and an interface can be used for HTTP content. These include the following.
- IHttpContent - a base interface representing an HTTP entity body and content headers.
- HttpBufferContent - HTTP content based on a stream.
- HttpFormUrlEncodedContent - HTTP content based on name/value data encoded using application/x-www-form-urlencoded MIME type.
- HttpMultipartContent - HTTP content that uses multipart/* MIME type.
- HttpMultipartFormDataContent - HTTP content that uses the encoded multipart/form-data MIME type.
- HttpStreamContent - HTTP content based on a stream.
- HttpStringContent - HTTP content based on a string.
A number of HttpClient methods don't need to set the Content property on the HttpRequestMessage. These include the following:
Headers Headers Headers Headers
Gets the collection of the HTTP request headers associated with the HttpRequestMessage.
public : HttpRequestHeaderCollection Headers { get; }public HttpRequestHeaderCollection Headers { get; }Public ReadOnly Property Headers As HttpRequestHeaderCollection// You can use this property in JavaScript.
- Value
- HttpRequestHeaderCollection HttpRequestHeaderCollection HttpRequestHeaderCollection HttpRequestHeaderCollection
The collection of HTTP request headers associated with the HttpRequestMessage.
Remarks
The Headers property returns an HttpRequestHeaderCollection object that can be used to get or set the specific headers on the HTTP request.
The Headers property represents the headers that an app developer can set, not all of the headers that may eventually be sent with the request. The HttpBaseProtocolFilter will add some additional headers.
- See Also
Method Method Method Method
Gets or sets the HTTP method to be performed on the request URI.
public : HttpMethod Method { get; set; }public HttpMethod Method { get; set; }Public ReadWrite Property Method As HttpMethod// You can use this property in JavaScript.
The HTTP method to be performed on the request URI.
Remarks
The standard HTTP methods include CONNECT, DELETE, GET, HEAD, OPTIONS, POST, PUT, and TRACE.
Properties Properties Properties Properties
Gets a set of properties on the HttpRequestMessage instance that are for use by the developer.
public : IMap<string, object> Properties { get; }public IDictionary<string, object> Properties { get; }Public ReadOnly Property Properties As IDictionary<string, object>// You can use this property in JavaScript.
- Value
- IMap<PlatForm::String, PlatForm::Object> IDictionary<string, object> IDictionary<string, object> IDictionary<string, object>
A set of properties on the HttpRequestMessage instance that are for use by the developer.
RequestUri RequestUri RequestUri RequestUri
Gets or sets the Uri used for the HttpRequestMessage object.
public : Uri RequestUri { get; set; }public Uri RequestUri { get; set; }Public ReadWrite Property RequestUri As Uri// You can use this property in JavaScript.
Remarks
The value of the RequestUri must not be a relative Uri.
TransportInformation TransportInformation TransportInformation TransportInformation
Get information about the underlying transport socket used by an HTTP connection.
public : HttpTransportInformation TransportInformation { get; }public HttpTransportInformation TransportInformation { get; }Public ReadOnly Property TransportInformation As HttpTransportInformation// You can use this property in JavaScript.
- Value
- HttpTransportInformation HttpTransportInformation HttpTransportInformation HttpTransportInformation
Information about the underlying transport socket used by an HTTP connection.
Remarks
The primary use of the TransportInformation property is to get SSL information when SSL is used for the HTTP connection. This is commonly used to get the SSL certificate from the server or to view a list of errors that occurred when making an SSL connection.
Methods
Close() Close() Close() Close()
Closes the HttpRequestMessage instance and releases allocated resources.
public : void Close()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
Remarks
The Close method releases allocated resources used by the HttpRequestMessage instance. The Close method can manage the lifetime of system resources (memory for the HttpRequestMessage, for example) used by a Windows Runtime object.
In the .NET Framework 4.5, this method projects as the Dispose method. In Visual C++ component extensions (C++/CX), this method projects as the destructor (delete operator).
Apps written in JavaScript, C#, or VB.NET use garbage collection to release resources. So the HttpRequestMessage object and associated resources doesn't get released until the garbage collection pass runs. The Close method allows an app to release these resources early rather than waiting for the object to be released by garbage collection.
Apps written in C++ or CX don't have a Close method since these apps can destroy the object. In C++ and CX, objects are released when they fall out of program scope or as part of the destructor (delete operator) for the object.
Dispose() Dispose() Dispose() Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
This member is not implemented in C++void Dispose()Sub Disposevoid Dispose()
ToString() ToString() ToString() ToString()
Returns a string that represents the current HttpRequestMessage object.
public : PlatForm::String ToString()public string ToString()Public Function ToString() As string// You can use this method in JavaScript.
A string that represents the current object.