Пример #1
0
        /// <summary>
        /// Perform a GET request and return the results as a stream of bytes
        /// </summary>
        /// <param name="prog">Progress tracker (defaults to no progress tracking)</param>
        /// <returns>A stream that contains the response body, and an HTTP status code</returns>
        public static async Task <HttpWebResponse> GetAsync(this HttpWebRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return((HttpWebResponse)await request
                   .Method(HttpMethods.GET)
                   .GetResponseAsync()
                   .ConfigureAwait(false));
        }
Пример #2
0
        /// <summary>
        /// Perform a DELETE request, writing the body through a stream, and return the results as a stream.
        /// </summary>
        /// <param name="prog">Progress tracker (defaults to no progress tracking)</param>
        /// <returns>A stream that contains the response body, and an HTTP status code</returns>
        public static async Task <HttpWebResponse> DeleteAsync(this HttpWebRequest request, Func <BodyInfo> getInfo, Action <Stream> writeBody, IProgress prog)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            request = request.Method(HttpMethods.DELETE);
            await request
            .WriteBodyAsync(getInfo, writeBody, prog)
            .ConfigureAwait(false);

            return((HttpWebResponse)await request.GetResponseAsync()
                   .ConfigureAwait(false));
        }