C# 如何解决Web客户端上传文件“远程服务器返回错误:(405)方法不允许。”?
您好,我想将本地的 html 文件上传到服务器中的远程文件夹,该文件夹包含带有 geoserver 元素的数据目录,这是我的代码:
public void CopyWS(string SourcePath, string DestinationPath)
{
try
{
string SourcePath = Path.GetFullPath("Result.html");
string DestinationPath = @"http://xx.xx.xxx.:8080/geoserver/rest/workspaces/";
string authInfo = "admin:geoserver";
WebClient client = new WebClient();
client.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(authInfo));
client.UploadFile(DestinationPath, "PUT", SourcePath);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
我收到以下错误“不允许错误 405 方法”。我尝试使用不同的方法,例如 post 而不是 put,但我遇到了相同的错误。
编辑:有人认为这可能是一个安全问题吗?使用UploadData,我遇到了相同的错误
编辑:经过长时间使用不同方法(UploadDatat即)进行测试后,我总是遇到相同的错误。我一直在搜索和阅读该错误找不到任何真正有用的东西。
编辑:有什么想法吗?
提前致谢
Hello I want to upload a html file that is in my local to a remote folder in a server that contains a data dir with geoserver elements, and here is my code:
public void CopyWS(string SourcePath, string DestinationPath)
{
try
{
string SourcePath = Path.GetFullPath("Result.html");
string DestinationPath = @"http://xx.xx.xxx.:8080/geoserver/rest/workspaces/";
string authInfo = "admin:geoserver";
WebClient client = new WebClient();
client.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(authInfo));
client.UploadFile(DestinationPath, "PUT", SourcePath);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
I´m getting the following error "Error 405 method not allowed". I´m trying with different methods like post instead of put but I´m getting the same error.
EDIT: Anybody think that maybe can be a security problem? With UploadData I´m getting the same error
EDIT: After a long time testing with different methods (UploadDatat i.e) I´m getting always the same error.I've been searching and reading around to that and couldn't fine anything really useful.
EDIT: Any idea?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PUT
未配置...通常PUT
(但并非总是)意味着服务器理解WebDAV
...HTTP 上传通常通过
POST
完成...另一种可能性是某些代理阻止
PUT
。编辑 - 根据评论:
POST 请求需要以不同的方式构建,并且取决于服务器期望它们的方式...有关某些示例代码,请参阅 使用 HTTPWebrequest 上传文件(multipart/form-data)
PUT
is not configured... usuallyPUT
(but not always) means that the server understandsWebDAV
...HTTP
uploads are usually done viaPOST
...another possibility would be that some proxy blocks
PUT
.EDIT - as per comment:
POST requests need to the be built differentley and depends on how the server expects them... for some sample code see Upload files with HTTPWebrequest (multipart/form-data)