// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Net.Http.Formatting; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; using System.Web.Http; namespace System.Net.Http { /// /// Extension methods that aid in making formatted requests using . /// [EditorBrowsable(EditorBrowsableState.Never)] public static class HttpClientExtensions { /// /// Sends a POST request as an asynchronous operation to the specified Uri with the given serialized /// as JSON. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PostAsJsonAsync(this HttpClient client, string requestUri, T value) { return client.PostAsJsonAsync(requestUri, value, CancellationToken.None); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with the given serialized /// as JSON. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PostAsJsonAsync(this HttpClient client, string requestUri, T value, CancellationToken cancellationToken) { return client.PostAsync(requestUri, value, new JsonMediaTypeFormatter(), cancellationToken); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with the given serialized /// as JSON. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A task object representing the asynchronous operation. public static Task PostAsJsonAsync(this HttpClient client, Uri requestUri, T value) { return client.PostAsJsonAsync(requestUri, value, CancellationToken.None); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with the given serialized /// as JSON. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. public static Task PostAsJsonAsync(this HttpClient client, Uri requestUri, T value, CancellationToken cancellationToken) { return client.PostAsync(requestUri, value, new JsonMediaTypeFormatter(), cancellationToken); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with the given serialized /// as XML. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PostAsXmlAsync(this HttpClient client, string requestUri, T value) { return client.PostAsXmlAsync(requestUri, value, CancellationToken.None); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with the given serialized /// as XML. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PostAsXmlAsync(this HttpClient client, string requestUri, T value, CancellationToken cancellationToken) { return client.PostAsync(requestUri, value, new XmlMediaTypeFormatter(), cancellationToken); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with the given serialized /// as XML. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A task object representing the asynchronous operation. public static Task PostAsXmlAsync(this HttpClient client, Uri requestUri, T value) { return client.PostAsXmlAsync(requestUri, value, CancellationToken.None); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with the given serialized /// as XML. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. public static Task PostAsXmlAsync(this HttpClient client, Uri requestUri, T value, CancellationToken cancellationToken) { return client.PostAsync(requestUri, value, new XmlMediaTypeFormatter(), cancellationToken); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PostAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter) { return client.PostAsync(requestUri, value, formatter, CancellationToken.None); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PostAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter, CancellationToken cancellationToken) { return client.PostAsync(requestUri, value, formatter, mediaType: (MediaTypeHeaderValue)null, cancellationToken: cancellationToken); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PostAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter, string mediaType) { return client.PostAsync(requestUri, value, formatter, mediaType, CancellationToken.None); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PostAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter, string mediaType, CancellationToken cancellationToken) { return client.PostAsync(requestUri, value, formatter, ObjectContent.BuildHeaderValue(mediaType), cancellationToken); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "The caller is responsible for disposing the object")] [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "The called method will convert to Uri instance.")] public static Task PostAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType, CancellationToken cancellationToken) { if (client == null) { throw Error.ArgumentNull("client"); } var content = new ObjectContent(value, formatter, mediaType); return client.PostAsync(requestUri, content, cancellationToken); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// A task object representing the asynchronous operation. public static Task PostAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter) { return client.PostAsync(requestUri, value, formatter, CancellationToken.None); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. public static Task PostAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter, CancellationToken cancellationToken) { return client.PostAsync(requestUri, value, formatter, mediaType: (MediaTypeHeaderValue)null, cancellationToken: cancellationToken); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A task object representing the asynchronous operation. public static Task PostAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter, string mediaType) { return client.PostAsync(requestUri, value, formatter, mediaType, CancellationToken.None); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. public static Task PostAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter, string mediaType, CancellationToken cancellationToken) { return client.PostAsync(requestUri, value, formatter, ObjectContent.BuildHeaderValue(mediaType), cancellationToken); } /// /// Sends a POST request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "The caller is responsible for disposing the object")] public static Task PostAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType, CancellationToken cancellationToken) { if (client == null) { throw Error.ArgumentNull("client"); } var content = new ObjectContent(value, formatter, mediaType); return client.PostAsync(requestUri, content, cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with the given serialized /// as JSON. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PutAsJsonAsync(this HttpClient client, string requestUri, T value) { return client.PutAsJsonAsync(requestUri, value, CancellationToken.None); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with the given serialized /// as JSON. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PutAsJsonAsync(this HttpClient client, string requestUri, T value, CancellationToken cancellationToken) { return client.PutAsync(requestUri, value, new JsonMediaTypeFormatter(), cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with the given serialized /// as JSON. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A task object representing the asynchronous operation. public static Task PutAsJsonAsync(this HttpClient client, Uri requestUri, T value) { return client.PutAsJsonAsync(requestUri, value, CancellationToken.None); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with the given serialized /// as JSON. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. public static Task PutAsJsonAsync(this HttpClient client, Uri requestUri, T value, CancellationToken cancellationToken) { return client.PutAsync(requestUri, value, new JsonMediaTypeFormatter(), cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with the given serialized /// as XML. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PutAsXmlAsync(this HttpClient client, string requestUri, T value) { return client.PutAsXmlAsync(requestUri, value, CancellationToken.None); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with the given serialized /// as XML. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PutAsXmlAsync(this HttpClient client, string requestUri, T value, CancellationToken cancellationToken) { return client.PutAsync(requestUri, value, new XmlMediaTypeFormatter(), cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with the given serialized /// as XML. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A task object representing the asynchronous operation. public static Task PutAsXmlAsync(this HttpClient client, Uri requestUri, T value) { return client.PutAsXmlAsync(requestUri, value, CancellationToken.None); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with the given serialized /// as XML. /// /// /// This method uses the default instance of . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. public static Task PutAsXmlAsync(this HttpClient client, Uri requestUri, T value, CancellationToken cancellationToken) { return client.PutAsync(requestUri, value, new XmlMediaTypeFormatter(), cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PutAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter) { return client.PutAsync(requestUri, value, formatter, CancellationToken.None); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PutAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter, CancellationToken cancellationToken) { return client.PutAsync(requestUri, value, formatter, mediaType: (MediaTypeHeaderValue)null, cancellationToken: cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PutAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter, string mediaType) { return client.PutAsync(requestUri, value, formatter, mediaType, CancellationToken.None); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] public static Task PutAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter, string mediaType, CancellationToken cancellationToken) { return client.PutAsync(requestUri, value, formatter, ObjectContent.BuildHeaderValue(mediaType), cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings", MessageId = "1#", Justification = "We want to support URIs as strings")] [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "The caller is responsible for disposing the object")] [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "The called method will convert to Uri instance.")] public static Task PutAsync(this HttpClient client, string requestUri, T value, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType, CancellationToken cancellationToken) { if (client == null) { throw Error.ArgumentNull("client"); } var content = new ObjectContent(value, formatter, mediaType); return client.PutAsync(requestUri, content, cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// A task object representing the asynchronous operation. public static Task PutAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter) { return client.PutAsync(requestUri, value, formatter, CancellationToken.None); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. public static Task PutAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter, CancellationToken cancellationToken) { return client.PutAsync(requestUri, value, formatter, mediaType: (MediaTypeHeaderValue)null, cancellationToken: cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A task object representing the asynchronous operation. public static Task PutAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter, string mediaType) { return client.PutAsync(requestUri, value, formatter, mediaType, CancellationToken.None); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. public static Task PutAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter, string mediaType, CancellationToken cancellationToken) { return client.PutAsync(requestUri, value, formatter, ObjectContent.BuildHeaderValue(mediaType), cancellationToken); } /// /// Sends a PUT request as an asynchronous operation to the specified Uri with /// serialized using the given . /// /// The type of . /// The client used to make the request. /// The Uri the request is sent to. /// The value that will be placed in the request's entity body. /// The formatter used to serialize the . /// The authoritative value of the request's content's Content-Type header. Can be null in which case the /// formatter's default content type will be used. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task object representing the asynchronous operation. [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "The caller is responsible for disposing the object")] public static Task PutAsync(this HttpClient client, Uri requestUri, T value, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType, CancellationToken cancellationToken) { if (client == null) { throw Error.ArgumentNull("client"); } var content = new ObjectContent(value, formatter, mediaType); return client.PutAsync(requestUri, content, cancellationToken); } } }