简体   繁体   中英

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

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 ie) 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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM