0
Thanks for the reply.
Yes, that's a working little hack but I was wondering on how to download attachments over HTTP. WebClient.DownloadFile() for example will work only if the web server recognizes the mime type of the requested page, but will fail with the mentioned exception if it doesn't and serves the file as an attachment (like when you get prompted to download a file in the browser).
0
private string DownloadBnr()
{
string xml = string.Empty;
WebClient c = new WebClient();
Stream s = c.OpenRead("http://www.bnr.ro/nbrfxrates.xml");
try
{
int n, bloc = 64;
byte[] bytes = new byte[bloc];
do
{
n = s.Read(bytes, 0, bloc);
// The end of the file is reached.
if (n == 0)
break; //Normal condition, never reached at BNR
xml += Encoding.UTF8.GetString(bytes, 0, n);
} while (!xml.EndsWith("</DataSet>")); //Stupid, but working
}
finally
{
s.Close();
}
return xml;
}