How to get content from file from this URL?

前端 未结 4 2034
北海茫月
北海茫月 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:05

    var webRequest = WebRequest.Create(@"http://yourUrl");
    
    using (var response = webRequest.GetResponse())
    using(var content = response.GetResponseStream())
    using(var reader = new StreamReader(content)){
        var strContent = reader.ReadToEnd();
    }
    

    This will place the contents of the request into strContent.

    Or as adrianbanks mentioned below simply use WebClient.DownloadString()

提交回复
热议问题