C#如何解决Web客户端上载文件“远程服务器返回错误:(405)不允许的方法."? [英] C# How to solve Web Client Upload file "The remote server returned an error: (405) Method Not Allowed."?

查看:1153
本文介绍了C#如何解决Web客户端上载文件“远程服务器返回错误:(405)不允许的方法."?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想将本地的html文件上载到服务器的远程文件夹中,该服务器包含带有geoserver元素的数据目录,这是我的代码:

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);
        }

我收到以下错误不允许使用错误405方法".我正在尝试使用诸如 post 之类的不同方法,而不是 put ,但是我遇到了相同的错误.

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.

编辑:有人认为这可能是安全问题吗?有了UploadData,我得到了相同的错误

Anybody think that maybe can be a security problem? With UploadData I´m getting the same error

编辑:经过长时间使用不同方法(例如UploadDatat)的测试,我总是遇到相同的错误.我一直在搜索和阅读有关该内容的信息,但实际上并不能解决任何问题有用.

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.

有什么想法吗?

预先感谢

推荐答案

PUT未配置...通常PUT(但并非总是如此)意味着服务器可以理解WebDAV ... HTTP上传通常是通过POST ...

PUT is not configured... usually PUT (but not always) means that the server understands WebDAV... HTTP uploads are usually done via POST...

另一种可能是某些代理会阻止PUT.

another possibility would be that some proxy blocks PUT.

编辑-根据评论:

EDIT - as per comment:

POST请求需要以不同的方式构建,并取决于服务器对它们的期望...有关某些示例代码,请参见

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)

这篇关于C#如何解决Web客户端上载文件“远程服务器返回错误:(405)不允许的方法."?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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