c#下载字符串错误

本文关键字:错误 字符串 下载 | 更新日期: 2023-09-27 18:05:43

由于某些原因,当输入

    public static Thread UDP = new Thread(UDPFlood);
    public static string IP = GetIP();
    public static string ownerURL = "{url}";
    public static string GetIP()
    {
        ownerURL = ownerURL.Replace("{url}","http://www.test.com");
        WebClient ipGrabber = new WebClient();
        return ipGrabber.DownloadString(ownerURL + "/getIP.php");
    }

抛出这个错误:

系统。的类型初始化项的传播者。FormMain抛出了一个异常。——> System.Net.WebException:找不到"C:'getIP.php"文件。——> System.Net.WebException:找不到"C:'getIP.php"文件。--->System.IO.FileNotFoundException:无法找到文件"C:'getIP.php".

基本上,当使用字符串+/getIP.php时,它在我的计算机上查找目录,而不是在web上。

c#下载字符串错误

类初始化器可能在初始化ownerURL之前调用GetIP。因此,ownerURL.Replace调用没有做您想要的。

由于这个原因,我建议你避免使用静态初始化器;执行顺序难以预测