Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

c# - 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.

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

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.

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,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...