我有这段代码:
string downloadedString;
System.Net.WebClient client;
client = new System.Net.WebClient();
downloadedString = client.DownloadString(
"http://thebnet.x10.mx/HWID/BaseHWID/AlloweHwids.txt");
这是一个HWID类型的安全性(它将检查您的HWID以查看您是否被允许使用该程序)
无论如何,我希望能够一次放多行,例如:
xjh94jsl <-- Not a real HWID
t92jfgds <-- Also not real
能够逐个读取每一行,并将其更新为downloadedString。
答案 0 :(得分:18)
不要将网址作为字符串下载,请将其作为流阅读。
using System.IO;
using System.Net;
var url ="http://thebnet.x10.mx/HWID/BaseHWID/AlloweHwids.txt";
var client = new WebClient();
using (var stream = client.OpenRead(url))
using (var reader = new StreamReader(stream))
{
string line;
while ((line = reader.ReadLine()) != null)
{
// do stuff
}
}