远程文件到变量 (C#)

Remote File to Variables (C#)

我正在尝试为旧版 Toontown Online 使用的某种类型的文件创建 reader。它是 patcher.ver。我已经尝试从它所在的页面读取带有字典的变量,但似乎无法让它工作!

WebRequest request = WebRequest.Create(Form1.patcherBaseURL + "/patcher.ver");
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
string html = String.Empty;
using (StreamReader sr = new StreamReader(data))
{
    html = sr.ReadToEnd();
    var dic = File.ReadAllLines(html)
        .Select(l => l.Split(new[] { '=' }))
        .ToDictionary(s => s[0].Trim(), s => s[1].Trim());
    string PatchVerStrServer = dic["PATCHER_VERSION_STRING_SERVER"];

这是我尝试使用的代码。但是我不断收到异常 "illegal characters in path"

我正在尝试读取的文件位于:http://dolimg.com/toontown/uk/patcher.ver

如有帮助,谢谢!我是 C# 的新手,我似乎找不到与此相关的任何内容。

试试下面的代码。 html 中有一些行被注释掉了,所以我使用了一个 where 来跳过这些行

WebRequest request = WebRequest.Create(Form1.patcherBaseURL + "/patcher.ver");
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
string html = String.Empty;
using (StreamReader sr = new StreamReader(data))
{
    html = sr.ReadToEnd();
    var dic = html
        .Split (new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
        .Where (line => !line.StartsWith("#"))        // Skip commented out lines
        .Select(line => line.Split(new[] { '=' }, 2)) // Beware: some values have spaces
        .ToDictionary(token => token[0].Trim(), token => token[1].Trim());

    string patchVerStrServer = dic["PATCHER_VERSION_STRING_SERVER"];
}