3

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

John Gilbert
  • 159
  • 1
  • 4
  • 18

1 Answers1

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)

Community
  • 1
  • 1
Yahia
  • 69,653
  • 9
  • 115
  • 144
  • Thanks for your reply Yahia but with POST I´m getting Error 400 Bad Request – John Gilbert Aug 11 '11 at 11:05
  • In your example they are using HTTPWebrequest is not possible with WebClient? – John Gilbert Aug 11 '11 at 11:26
  • you can try `client.UploadFile(DestinationPath, SourcePath);` BUT as in my EDIT the server might expect some specific things in a `POST` and then you better use HTTPWebRequest... – Yahia Aug 11 '11 at 11:31
  • Thanks I´m finishing with my tests about Web Client and I will start with HTTPWebrequest I thougth that with WebClient was possible but now I´m not sure – John Gilbert Aug 12 '11 at 08:01