C# How to solve Web Client Upload file “The remote server returned an error: (405) Method Not Allowed.”?

痞子三分冷 提交于 2019-12-12 01:52:43

问题


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


回答1:


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

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)



来源:https://stackoverflow.com/questions/7024523/c-sharp-how-to-solve-web-client-upload-file-the-remote-server-returned-an-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!