Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Reading text file with HttpWebRequest / HttpWebResponse

BobClemensBobClemens USMember ✭✭

Trying to read the contents of a text file that resides on the Web.
The following code works fine.
However, if the file has an arbitrary extension other than .txt or .html, the GetResponse returns error 404, Not Found (even though the file exists.)
Is there any way I can read files with arbitrary extensions? For example,

`   string url = @"";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    using (TextReader reader = new StreamReader(response.GetResponseStream()))
        string s = reader.ReadToEnd();



Best Answer


  • JohnHardmanJohnHardman GBUniversity admin

    @BobClemens - As per the post by @Amar_Bait above (it's probably the second point @Amar_Bait raised). As an aside, you might want to make one change - if your files are large, you might want to consider using ReadAsStreamAsync() rather than ReadAsStringAsync().

Sign In or Register to comment.