错误:(405)将文件上传到https时不允许使用方法

时间:2017-02-15 05:44:17

标签: c# file-upload https

编写代码以将文件上传到https文件夹,如下所示

WebClient webClient = new WebClient();
            string webAddress = null;
            try
            {
                webAddress = @"https://www.example.net/mydocs";
                webClient.UseDefaultCredentials = true;
                webClient.Credentials = CredentialCache.DefaultCredentials;

                WebRequest serverRequest = WebRequest.Create(webAddress);
                WebResponse serverResponse;
                serverResponse = serverRequest.GetResponse();
                serverResponse.Close();

                webClient.UploadFile(webAddress , "PUT", @"C:\d\1.xml");
                webClient.Dispose();
                webClient = null;
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }

webClient.UploadFile(webAddress , "PUT", @"C:\d\1.xml"); 返回错误

  

远程服务器返回错误:(405)Method Not Allowed。

1 个答案:

答案 0 :(得分:0)

看起来服务器上不支持方法PUT。确保支持正确的方法。您可以尝试使用POST

 webClient.UploadFile(webAddress , "POST", @"C:\d\1.xml");