public async Task <XmlDocumentWithNamespaceManager> ExecuteWebDavRequestAndReadResponse( Uri url, string httpMethod, int?depth, string ifMatch, string ifNoneMatch, string mediaType, string requestBody) { try { var response = await ExecuteWebDavRequest(url, httpMethod, depth, ifMatch, ifNoneMatch, mediaType, requestBody); using (response.Item2) { using (var responseStream = await response.Item2.Content.ReadAsStreamAsync()) { return(CreateXmlDocument(responseStream, response.Item3)); } } } catch (HttpRequestException x) { throw WebExceptionMapper.Map(x); } }
private static async Task EnsureSuccessStatusCode(HttpResponseMessage response) { if (!response.IsSuccessStatusCode) { string responseMessage = null; try { using (var responseStream = await response.Content.ReadAsStreamAsync()) { using (var reader = new StreamReader(responseStream, Encoding.UTF8)) { responseMessage = reader.ReadToEnd(); } } } catch (Exception x) { s_logger.Error("Exception while trying to read the error message.", x); } throw WebExceptionMapper.Map( new WebDavClientException( response.StatusCode, response.ReasonPhrase ?? response.StatusCode.ToString(), responseMessage, response.Headers != null ? (IHttpHeaders) new HttpResponseHeadersAdapter(response.Headers, response.Headers) : new NullHeaders())); } }
public async Task <IHttpHeaders> ExecuteWebDavRequestAndReturnResponseHeaders( Uri url, string httpMethod, int?depth, string ifMatch, string ifNoneMatch, string mediaType, string requestBody) { try { var result = await ExecuteWebDavRequest(url, httpMethod, depth, ifMatch, ifNoneMatch, mediaType, requestBody); using (var response = result.Item2) { return(new HttpResponseHeadersAdapter(result.Item1, response.Headers)); } } catch (HttpRequestException x) { throw WebExceptionMapper.Map(x); } }