简体   繁体   English

使用webclient上传文件405错误问题

[英]Using the webclient to upload a file 405 error problem

VS C# 2005

I am using the code below to upload a file to a server running windows IIS 5.1. 我使用下面的代码将文件上传到运行Windows IIS 5.1的服务器。

I am just testing on our local server running windows XP. 我只是在运行Windows XP的本地服务器上进行测试。 However, I keep getting the following error message: 但是,我不断收到以下错误消息:

The remote server returned an error (405) Method Not Allowed

I am sure this is a IIS problem maybe something to so with permissions. 我确信这是一个IIS问题可能是权限的事情。 However, I am configured IIS to allow read, write, and directory browsing. 但是,我配置IIS以允许读取,写入和目录浏览。

The config.xml file I am trying to upload is located in the same directory as the executable. 我尝试上传的config.xml文件与可执行文件位于同一目录中。

   private void upload_config_to_server()
   {
        Uri url = new Uri("http://10.10.10.3/softphone/config.xml");

        WebClient wc = new WebClient();
        if (!wc.IsBusy)
        {                
            try
            {
                wc.UploadFile(url, null, "config.xml");
            }
            catch (WebException webex)
            {
                Console.WriteLine("Web Exception {0}", webex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception {0}", ex.Message);
            }
        }
    }

Many thanks for any suggestions, 非常感谢任何建议,

Only registered file types can accept requests with a POST method in IIS. 只有已注册的文件类型才能在IIS中使用POST方法接受请求。 See this " How to resolve HTTP 405 " article for more details. 有关更多详细信息,请参阅“ 如何解析HTTP 405 ”一文。

Also, for posting the file, you need to make sure that server side script handles this upload properly, if you want it to appear in the folder you're uploading. 此外,要发布文件,您需要确保服务器端脚本正确处理此上载,如果您希望它出现在您上传的文件夹中。 Your URL (first argument in the wc.UploadFile) should be that server side script that handles the upload. 您的URL(wc.UploadFile中的第一个参数)应该是处理上载的服务器端脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM