简体   繁体   中英

error: (405) Method Not Allowed when uploading file to https

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.

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");

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