How to get content from file from this URL?

前端 未结 4 2026
北海茫月
北海茫月 2020-12-08 14:44

I have this URL: URL from Google

When open link in new tab, the browser force me download it. After download, I get a text file named \"s\". But I want use C# acces

4条回答
  •  失恋的感觉
    2020-12-08 15:13

    Since this question and my previous answer is fairly old now, a more modern answer would be to use HttpClient from System.Net.Http

    using System.Net.Http;
    
    namespace ConsoleApp2
    {
        class Program
        {
            async static void Main(string[] args)
            {
                HttpClient client = new HttpClient();
                string result = await client.GetStringAsync("https://example.com/test.txt");
            }
        }
    }
    

    If not within an async function, then:

    string result = client.GetStringAsync("https://example.com/test.txt").Result;
    

提交回复
热议问题