/// <summary>
 /// Creates a new <see cref="WebClientResponseWrapper"/> with the given <see cref="HttpWebResponse"/> and <see cref="HttpWebRequest"/>.
 /// </summary>
 /// <param name="response"></param>
 /// <param name="request"></param>
 /// <param name="exception"></param>
 /// <param name="statusCodeOverride"></param>
 public WebClientResponseWrapper(HttpWebResponse?response, HttpWebRequest request, Exception?exception = null, int?statusCodeOverride = null)
 {
     _                   = request ?? throw new ArgumentNullException(nameof(request), $"Request cannot be null when creating a {nameof(WebClientResponseWrapper)}");
     _response           = response;
     _statusCodeOverride = statusCodeOverride;
     Exception           = exception;
     RequestUri          = request.RequestUri;
     if (response != null)
     {
         Content = new WebClientContent(response);
     }
     _headers = new Dictionary <string, IEnumerable <string> >();
     if (_response?.Headers != null)
     {
         foreach (var headerKey in _response.Headers.AllKeys)
         {
             _headers.Add(headerKey, new string[] { _response.Headers[headerKey] });
         }
     }
 }
Пример #2
0
 public WebClientResponseWrapper(HttpWebResponse response, HttpWebRequest request, Exception exception = null, int?statusCodeOverride = null)
 {
     _response           = response;
     _request            = request;
     _statusCodeOverride = statusCodeOverride;
     Exception           = exception;
     RequestUri          = request?.RequestUri;
     if (response != null)
     {
         Content = new WebClientContent(_response);
     }
     _headers = new Dictionary <string, IEnumerable <string> >();
     if (_response?.Headers != null)
     {
         foreach (var headerKey in _response.Headers.AllKeys)
         {
             _headers.Add(headerKey, new string[] { _response.Headers[headerKey] });
         }
     }
 }