How to read a file from internet?

后端 未结 7 1909
甜味超标
甜味超标 2020-12-03 03:05

simple question: I have an file online (txt). How to read it and check if its there? (C#.net 2.0)

7条回答
  •  鱼传尺愫
    2020-12-03 03:27

    This is too much easier:

    using System.Net;
    using System.IO;
    

    ...

        using (WebClient client = new WebClient()) {
            //... client.options
            Stream stream = client.OpenRead("http://.........");
            using (StreamReader reader = new StreamReader(stream)) {
                string content = reader.ReadToEnd();
            }
        }
    

    "WebClient" and "StreamReader" are disposables. The content of file will be into "content" var.

    The client var contains several configuration options.

    The default configuration could be called as:

    string content = new WebClient().DownloadString("http://.........");
    

提交回复
热议问题