WebResponse - ReadToEnd
A WebResponse extension method that reads the response stream to the end.
public static void Main() { WebRequest request = WebRequest.Create("https://github.com/"); WebResponse value = request.GetResponseSafe(); string str = null; using (value) { //C# Extension Method: WebResponse - ReadToEnd str = value.ReadToEnd(); } Console.WriteLine(str); }
View Source
using System.IO; using System.Net; public static partial class Extensions { /// <summary> /// A WebResponse extension method that reads the response stream to the end. /// </summary> /// <param name="this">The @this to act on.</param> /// <returns>The response stream as a string, from the current position to the end.</returns> public static string ReadToEnd(this WebResponse @this) { using (Stream stream = @this.GetResponseStream()) { using (var reader = new StreamReader(stream)) { return reader.ReadToEnd(); } } } }