How to download direct TXT file

0

I uploaded a file to a WEB server, but when I use this code:

 WebClient update = new WebClient();
string Teste = update.DownloadString("http://testexxx.000webhostapp.com/teste.txt");

Returns this error: ConfigurationErrorsException: Element not recognized.

Because he is not downloading directly from the file, because when he opens the file on the site he shows what is inside and does not download, how can I correct this?

    
asked by anonymous 29.05.2018 / 18:03

1 answer

1

Set the header from WebClient to Text/Plain :

using (WebClient wc = new WebClient())
{
    wc.Headers.Set("Content-Type", "text/plain");
    url = "http://www.dominio.com.br/teste.txt";
    string retorno = wc.DownloadString(url);
}

Edit:

Using the pastebin link:

using (WebClient wc = new WebClient())
{
    //retorno = wc.DownloadString(url);

    url = "https://pastebin.com/raw/xdTbdD5P";
    wc.Headers.Set("Content-Type", "text/plain");
    retorno = wc.DownloadString(url);

}
  

Result:

    
29.05.2018 / 18:39