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

Posted

技术标签:

【中文标题】错误:(405) 将文件上传到 https 时不允许使用方法【英文标题】:error: (405) Method Not Allowed when uploading file to https 【发布时间】:2017-02-15 05:44:17 【问题描述】:

写了一个代码将文件上传到 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。

【问题讨论】:

您上传文件的网站是否允许使用动词 PUT 我过去在访问我的服务时看到了这个错误。它主要与证券或权利有关。更好的是检查事件日志以了解其确切原因。否则,重新启动应用程序池并检查它是否有效 @Sachu,是否支持 NTLM? ***.com/questions/7024523/… 的可能重复项 试试这个***.com/questions/10134632/… .. 还要确保你在上传的同一个文件夹上有写权限 【参考方案1】:

看起来服务器不支持PUT 方法。确保它是支持的正确方法。你可以试试POST

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

【讨论】:

我将方法从“PUT”更改为“POST”,但仍然在 MVC 中遇到同样的错误。

以上是关于错误:(405) 将文件上传到 https 时不允许使用方法的主要内容,如果未能解决你的问题,请参考以下文章