0

Wrote a code to upload file to a https folder as below

WebClient webClient = new WebClient();
            string webAddress = null;
            try
            {
                webAddress = @"https://www.example.net/mydocs";
                webClient.UseDefaultCredentials = true;
                webClient.Credentials = CredentialCache.DefaultCredentials;

                WebRequest serverRequest = WebRequest.Create(webAddress);
                WebResponse serverResponse;
                serverResponse = serverRequest.GetResponse();
                serverResponse.Close();

                webClient.UploadFile(webAddress , "PUT", @"C:\d\1.xml");
                webClient.Dispose();
                webClient = null;
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }

the line webClient.UploadFile(webAddress , "PUT", @"C:\d\1.xml"); returning an error

The remote server returned an error: (405) Method Not Allowed.

Sachu
  • 7,555
  • 7
  • 55
  • 94
  • Does your website where you are uploading files allows the Verb `PUT` ? – Mairaj Ahmad Feb 15 '17 at 05:51
  • I've seen this error while accessing my services in the past. it has mostly to do with securities or rights. better is to check eventlog to get the exact reason of it. otherwise, restart the app pool and check if that works or not – Dirty Developer Feb 15 '17 at 05:51
  • @Sachu,Does NTLM is supported? – Dirty Developer Feb 15 '17 at 06:09
  • possible duplicate of http://stackoverflow.com/questions/7024523/c-sharp-how-to-solve-web-client-upload-file-the-remote-server-returned-an-error – Dirty Developer Feb 15 '17 at 06:12
  • try this http://stackoverflow.com/questions/10134632/the-remote-server-returned-an-error-405-method-not-allowed-wcf-rest-service .. Also make sure you have write permisson on the same folder where you are uploading – Dirty Developer Feb 15 '17 at 06:13

1 Answers1

0

Looks like the method PUT is not supported on the server. Make sure it's the correct method supported. You can try with POST

 webClient.UploadFile(webAddress , "POST", @"C:\d\1.xml");
Pradeep Kumar
  • 1,281
  • 7
  • 9
  • I changed the Method from "PUT" to "POST" but still, I am getting the same error in MVC. – Raji Nov 20 '18 at 05:41