Beispiel #1
0
        /// <summary>
        /// Sends an asynchronous HTTP request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="httpMethod">HTTP method of the request</param>
        /// <param name="data">Contents of the request body.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation. Optional.</param>
        /// <param name="completionOption">The HttpCompletionOption used in the request. Optional.</param>
        /// <returns>
        /// A Task whose result is the received HttpResponseMessage.
        /// </returns>
        public static async Task <HttpResponseMessage> SendXmlAsync(this IFlurlRequest request, HttpMethod httpMethod, object data,
                                                                    CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
        {
            var content = new CapturedXmlContent(request.Settings.XmlSerializer().Serialize(data), request.GetMediaType());

            return(await request.SendAsync(httpMethod, content, cancellationToken, completionOption));
        }
        /// <summary>
        /// Sends an asynchronous POST request.
        /// </summary>
        /// <param name="data">Contents of the request body.</param>
        /// <returns>A Task whose result is the received HttpResponseMessage.</returns>
        public static Task <HttpResponseMessage> PostXmlAsync(this FlurlClient client, object data)
        {
            var content = new CapturedXmlContent(client.Settings.XmlSerializer().Serialize(data));

            return(client.SendAsync(HttpMethod.Post, content: content));
        }