c# - 如何从此 URL 获取文件内容?

标签 c# url

我有这个网址:URL from Google

在新标签页中打开链接时,浏览器强制我下载它。下载后,我得到一个名为“s”的文本文件。但我想使用 C# 访问此 URL 并获取其文本,不要将其作为文件保存到计算机。有什么办法吗?

最佳答案

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();
}

这会将请求的内容放入 strContent。

或作为 adrianbanks下面提到的只需使用WebClient.DownloadString()

关于c# - 如何从此 URL 获取文件内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12240857/

相关文章:

c# - 复杂的 Linq C# 查询

C# 机会游戏

postgresql - PostgreSQL 中 URL 的数据类型

magento - 从旧 url Magento 重定向到新 url

c# - 为什么 if 语句表达式不被视为条件?

c# - 流利的断言 : Dictionary Should BeEquivalentTo Excluding Property on Dictionary Value

c# - 使用 c# 写入 Amazon s3 存储桶上的文件

iphone - 如何制作 URL/电话可点击的 UILabel?

ios - 使用 swift 5 请求 AlamoFire url

python - 如何取消缩短 URL?