0

在这里需要帮助,即使我搜索了解决方案,也遇到了这个错误,但仍然无法帮助我..

我想用HTTP协议下载文件,但使用不同的PORT,这意味着不使用端口80,而是使用5151等其他端口。代码在C#中运行良好,编译没有任何错误。在调试过程中,它说无法找到路径/URL,但路径/URL 在我的浏览器中使用端口 5151 工作正常(http://localhost:5151,工作得很好)..

有什么想法吗?

以下是代码,我应该添加任何遗漏吗?

client = new WebClient();
            try
            {
                client.DownloadFile(@""+httpAddr + ":5151/factionusers.log", "factionusers.log");
            }
            catch
            {
                client.DownloadFile(@""+httpAddr2 + ":5151/factionusers.log", "factionusers.log");
            }
4

1 回答 1

2

也许您在 httpAddr 变量中添加一个“/”。

static void Main()
    {
        string httpAddr = "http://192.168.56.101";
         var  client = new WebClient();
        try
        {
            client.DownloadFile(@"" + httpAddr + ":5151/readme.txt", "readme.txt");
        }
        catch
        {
            client.DownloadFile(@"" + httpAddr + ":5151/readme.txt", "readme.txt");
        }
    }

在我的电脑中。进展顺利。

于 2012-12-31T01:47:17.880 回答