Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Reading text file with HttpWebRequest / HttpWebResponse

$
0
0

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, myFile.xyz.

`   string url = @"http://www.xxxx.com/xxxx/myfile.txt";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    using (TextReader reader = new StreamReader(response.GetResponseStream()))
    {
        string s = reader.ReadToEnd();
        Console.WriteLine(s);
    }

}

`


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>