使用网络客户端上传文件405错误问题 [英] Using the webclient to upload a file 405 error problem

查看:90
本文介绍了使用网络客户端上传文件405错误问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS C# 2005

我正在使用下面的代码将文件上传到运行Windows IIS 5.1的服务器.

I am using the code below to upload a file to a server running windows IIS 5.1.

我只是在运行Windows XP的本地服务器上进行测试.但是,我不断收到以下错误消息:

I am just testing on our local server running windows XP. However, I keep getting the following error message:

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

我确定这是一个IIS问题,也许可以通过权限解决.但是,我将IIS配置为允许读取,写入和目录浏览.

I am sure this is a IIS problem maybe something to so with permissions. However, I am configured IIS to allow read, write, and directory browsing.

我要上传的config.xml文件与可执行文件位于同一目录中.

The config.xml file I am trying to upload is located in the same directory as the executable.

   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,

推荐答案

只有注册的文件类型才能在IIS中接受带有POST方法的请求.有关更多详细信息,请参见这篇"如何解析HTTP 405 "文章.

Only registered file types can accept requests with a POST method in IIS. See this "How to resolve HTTP 405" article for more details.

此外,要发布文件,还需要确保服务器端脚本能够正确处理此上载,如果希望它出现在要上载的文件夹中.您的网址(wc.UploadFile中的第一个参数)应该是处理上传的服务器端脚本.

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.

这篇关于使用网络客户端上传文件405错误问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆