public async Task <ResponseDetails> ReadRequestToEnd2Async(HttpWebRequest request) { using (var response = await request.GetResponseAsync().TimeoutAfter(shellService.Settings.TimeOut) as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.Found || response.StatusCode == HttpStatusCode.Moved) { response.Close(); if (response.Headers.AllKeys.Contains("Set-Cookie")) { cookieService.SetUriCookie(CookieParser.GetAllCookiesFromHeader(response.Headers["Set-Cookie"], "www.tumblr.com")); } return(new ResponseDetails() { HttpStatusCode = response.StatusCode, RedirectUrl = response.Headers["Location"] }); } using (Stream stream = GetStreamForApiRequest(response.GetResponseStream())) { using (var buffer = new BufferedStream(stream)) { using (var reader = new StreamReader(buffer)) { string content = reader.ReadToEnd(); return(new ResponseDetails() { HttpStatusCode = response.StatusCode, Response = content }); } } } } }