将URL从URL下载到字符串
答
string contents;
using (var wc = new System.Net.WebClient())
contents = wc.DownloadString(url);
答
使用Web客户端
var result = string.Empty;
using (var webClient = new System.Net.WebClient())
{
result = webClient.DownloadString("http://some.url");
}
+0
一分钟太晚了! – 2017-02-26 02:23:10
答
使用这种代码只需
var r= string.Empty;
using (var web = new System.Net.WebClient())
r= web.DownloadString("http://TEST.COM");
答
using System.IO;
using System.Net;
WebClient client = new WebClient();
string dnlad = client.DownloadString("http://www.stackoverflow.com/");
File.WriteAllText(@"c:\Users\Admin\Desktop\Data1.txt", dnlad);
得到它从MVA 希望它有助于
这就是为什么我爱的.NET库.. – 2010-07-12 20:27:06
噢好...我希望这是这么简单! – John 2011-07-08 20:15:26
正如@CaffGeek所指出的那样,您会想要在'using'块中处理'WebClient'。 – TrueWill 2015-07-08 13:23:58