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.

5
  • Does your website where you are uploading files allows the Verb PUT ? Commented Feb 15, 2017 at 5: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 Commented Feb 15, 2017 at 5:51
  • @Sachu,Does NTLM is supported? Commented Feb 15, 2017 at 6:09
  • possible duplicate of stackoverflow.com/questions/7024523/… Commented Feb 15, 2017 at 6:12
  • try this stackoverflow.com/questions/10134632/… .. Also make sure you have write permisson on the same folder where you are uploading Commented Feb 15, 2017 at 6:13

1 Answer 1

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"); 
Sign up to request clarification or add additional context in comments.

1 Comment

I changed the Method from "PUT" to "POST" but still, I am getting the same error in MVC.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.