C#C
C#4y ago
Hercules

❔ Would it be the fastest way to read text from a website with HttpWebRequest?

Im curious to know what would be the fastest way to read text from links such as

https://www.gutenberg.org/cache/epub/69354/pg69354.txt

There are other formats that are bigger in size but this is one the smaller ones.


var request = new HttpRequestMessage(HttpMethod.Get,"https://www.gutenberg.org/cache/epub/69354/pg69354.txt");
var response = await Client.SendAsync(request);

if (!response.IsSuccessStatusCode)
            { 
                return false;
            }

Stream stream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(stream);

return streamReader.ReadToEnd(); // returns a long string


Is there any other ways to improve it. Maybe make it thread safe probably if i'm going to make multiple url requests at once. (thats for another post).
Was this page helpful?