HttpRequestMessageExtensions Class¶
Methods¶
-
CreateErrorResponse
(System.Net.Http.HttpRequestMessage, InvalidByteRangeException)¶ Helper method for creating an [System.Net.Http.HttpResponseMessage]() message with a “416 (Requested Range Not Satisfiable)” status code. This response can be used in combination with the @!:ByteRangeStreamContent- to indicate that the requested range or ranges do not overlap with the current resource. The response contains a “Content-Range” header indicating the valid upper and lower bounds for requested ranges.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- invalidByteRangeException (InvalidByteRangeException) – An @!:InvalidByteRangeException- instance, typically thrown by a @!:ByteRangeStreamContent- instance.
Return type: System.Net.Http.HttpResponseMessage
Returns: An 416 (Requested Range Not Satisfiable) error response with a Content-Range header indicating the valid range.
public static HttpResponseMessage CreateErrorResponse(HttpRequestMessage request, InvalidByteRangeException invalidByteRangeException)
-
CreateErrorResponse
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary) Helper method that performs content negotiation and creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> representing an error with an instance of <see cref=”!:ObjectContent<T>” /> wrapping an
<see cref=”T:System.Web.Http.HttpError” /> for model state <paramref name=”modelState” />. If no formatter is found, this method returns a response with status 406 NotAcceptable.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- modelState (Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary) – The model state.
Return type: System.Net.Http.HttpResponseMessage
Returns: An error response for <paramref name=”modelState” /> with status code <paramref name=”statusCode” />.
public static HttpResponseMessage CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, ModelStateDictionary modelState)
-
CreateErrorResponse
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, System.Exception) Helper method that performs content negotiation and creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> representing an error with an instance of <see cref=”!:ObjectContent<T>” /> wrapping an
<see cref=”T:System.Web.Http.HttpError” /> for exception <paramref name=”exception” />. If no formatter is found, this method returns a response with status 406 NotAcceptable.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- exception (System.Exception) – The exception.
Return type: System.Net.Http.HttpResponseMessage
Returns: An error response for <paramref name=”exception” /> with status code <paramref name=”statusCode” />.
public static HttpResponseMessage CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, Exception exception)
-
CreateErrorResponse
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, System.String) Helper method that performs content negotiation and creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> representing an error with an instance of <see cref=”!:ObjectContent<T>” /> wrapping an
<see cref=”T:System.Web.Http.HttpError” /> with message <paramref name=”message” />. If no formatter is found, this method returns a response with status 406 NotAcceptable.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- message (System.String) – The error message.
Return type: System.Net.Http.HttpResponseMessage
Returns: An error response with error message <paramref name=”message” /> and status code <paramref name=”statusCode” />.
public static HttpResponseMessage CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, string message)
-
CreateErrorResponse
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, System.String, System.Exception) Helper method that performs content negotiation and creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> representing an error with an instance of <see cref=”!:ObjectContent<T>” /> wrapping an
<see cref=”T:System.Web.Http.HttpError” /> with error message <paramref name=”message” /> for exception
<paramref name=”exception” />. If no formatter is found, this method returns a response with status 406 NotAcceptable.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- message (System.String) – The error message.
- exception (System.Exception) – The exception.
Return type: System.Net.Http.HttpResponseMessage
Returns: An error response for <paramref name=”exception” /> with error message <paramref name=”message” /> and status code <paramref name=”statusCode” />.
public static HttpResponseMessage CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, string message, Exception exception)
-
CreateErrorResponse
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, System.Web.Http.HttpError) Helper method that performs content negotiation and creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> representing an error with an instance of <see cref=”!:ObjectContent<T>” /> wrapping <paramref name=”error” /> as the content. If no formatter is found, this method returns a response with status 406 NotAcceptable.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- error (System.Web.Http.HttpError) – The error to wrap.
Return type: System.Net.Http.HttpResponseMessage
Returns: An error response wrapping <paramref name=”error” /> with status code <paramref name=”statusCode” />.
public static HttpResponseMessage CreateErrorResponse(HttpRequestMessage request, HttpStatusCode statusCode, HttpError error)
-
CreateResponse<T>
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, T)¶ Helper method that performs content negotiation and creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> with an instance of <see cref=”!:ObjectContent<T>” /> as the content if a formatter can be found. If no formatter is found, this method returns a response with status 406 NotAcceptable. configuration.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- value (T) – The value to wrap. Can be <c>null</c>.
Return type: System.Net.Http.HttpResponseMessage
Returns: A response wrapping <paramref name=”value” /> with <paramref name=”statusCode” />.
public static HttpResponseMessage CreateResponse<T>(HttpRequestMessage request, HttpStatusCode statusCode, T value)
-
CreateResponse<T>
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, T, MediaTypeFormatter) Helper method that creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> with an <see cref=”!:ObjectContent<T>” /> instance containing the provided <paramref name=”value” /> and the given <paramref name=”formatter” />.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- value (T) – The value to wrap. Can be <c>null</c>.
- formatter (MediaTypeFormatter) – The formatter to use.
Return type: System.Net.Http.HttpResponseMessage
Returns: A response wrapping <paramref name=”value” /> with <paramref name=”statusCode” />.
public static HttpResponseMessage CreateResponse<T>(HttpRequestMessage request, HttpStatusCode statusCode, T value, MediaTypeFormatter formatter)
-
CreateResponse<T>
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, T, MediaTypeFormatter, System.Net.Http.Headers.MediaTypeHeaderValue) Helper method that creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> with an <see cref=”!:ObjectContent<T>” /> instance containing the provided <paramref name=”value” /> and the given <paramref name=”formatter” />.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- value (T) – The value to wrap. Can be <c>null</c>.
- formatter (MediaTypeFormatter) – The formatter to use.
- mediaType (System.Net.Http.Headers.MediaTypeHeaderValue) – The media type override to set on the response’s content. Can be <c>null</c>.
Return type: System.Net.Http.HttpResponseMessage
Returns: A response wrapping <paramref name=”value” /> with <paramref name=”statusCode” />.
public static HttpResponseMessage CreateResponse<T>(HttpRequestMessage request, HttpStatusCode statusCode, T value, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType)
-
CreateResponse<T>
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, T, MediaTypeFormatter, System.String) Helper method that creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> with an <see cref=”!:ObjectContent<T>” /> instance containing the provided <paramref name=”value” /> and the given <paramref name=”formatter” />.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- value (T) – The value to wrap. Can be <c>null</c>.
- formatter (MediaTypeFormatter) – The formatter to use.
- mediaType (System.String) – The media type override to set on the response’s content. Can be <c>null</c>.
Return type: System.Net.Http.HttpResponseMessage
Returns: A response wrapping <paramref name=”value” /> with <paramref name=”statusCode” />.
public static HttpResponseMessage CreateResponse<T>(HttpRequestMessage request, HttpStatusCode statusCode, T value, MediaTypeFormatter formatter, string mediaType)
-
CreateResponse<T>
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, T, System.Collections.Generic.IEnumerable<MediaTypeFormatter>) Helper method that performs content negotiation and creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> with an instance of <see cref=”!:ObjectContent<T>” /> as the content if a formatter can be found. If no formatter is found, this method returns a response with status 406 NotAcceptable.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- value (T) – The value to wrap. Can be <c>null</c>.
- formatters (System.Collections.Generic.IEnumerable{MediaTypeFormatter}) –
Return type: System.Net.Http.HttpResponseMessage
Returns: A response wrapping <paramref name=”value” /> with <paramref name=”statusCode” />.
public static HttpResponseMessage CreateResponse<T>(HttpRequestMessage request, HttpStatusCode statusCode, T value, IEnumerable<MediaTypeFormatter> formatters)
-
CreateResponse<T>
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, T, System.Net.Http.Headers.MediaTypeHeaderValue) Helper method that creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> with an <see cref=”!:ObjectContent<T>” /> instance containing the provided <paramref name=”value” />. The given <paramref name=”mediaType” /> is used to find an instance of <see cref=”!:MediaTypeFormatter” />.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- value (T) – The value to wrap. Can be <c>null</c>.
- mediaType (System.Net.Http.Headers.MediaTypeHeaderValue) – The media type used to look up an instance of @!:MediaTypeFormatter-.
Return type: System.Net.Http.HttpResponseMessage
Returns: A response wrapping <paramref name=”value” /> with <paramref name=”statusCode” />.
public static HttpResponseMessage CreateResponse<T>(HttpRequestMessage request, HttpStatusCode statusCode, T value, MediaTypeHeaderValue mediaType)
-
CreateResponse<T>
(System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, T, System.String) Helper method that creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> with an <see cref=”!:ObjectContent<T>” /> instance containing the provided <paramref name=”value” />. The given <paramref name=”mediaType” /> is used to find an instance of <see cref=”!:MediaTypeFormatter” />.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- statusCode (System.Net.HttpStatusCode) – The status code of the created response.
- value (T) – The value to wrap. Can be <c>null</c>.
- mediaType (System.String) – The media type used to look up an instance of @!:MediaTypeFormatter-.
Return type: System.Net.Http.HttpResponseMessage
Returns: A response wrapping <paramref name=”value” /> with <paramref name=”statusCode” />.
public static HttpResponseMessage CreateResponse<T>(HttpRequestMessage request, HttpStatusCode statusCode, T value, string mediaType)
-
CreateResponse<T>
(System.Net.Http.HttpRequestMessage, T) Helper method that performs content negotiation and creates a <see cref=”T:System.Net.Http.HttpResponseMessage” /> with an instance of <see cref=”!:ObjectContent<T>” /> as the content and <see cref=”F:System.Net.HttpStatusCode.OK” /> as the status code if a formatter can be found. If no formatter is found, this method returns a response with status 406 NotAcceptable.
Arguments: - request (System.Net.Http.HttpRequestMessage) – The request.
- value (T) – The value to wrap. Can be <c>null</c>.
Return type: System.Net.Http.HttpResponseMessage
Returns: A response wrapping <paramref name=”value” /> with [System.Net.HttpStatusCode.OK]() status code.
public static HttpResponseMessage CreateResponse<T>(HttpRequestMessage request, T value)
-