编写代码以将文件上传到https文件夹,如下所示
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);
}
行webClient.UploadFile(webAddress , "PUT", @"C:\d\1.xml");
返回错误
远程服务器返回错误:(405)Method Not Allowed。
答案 0 :(得分:0)
看起来服务器上不支持方法PUT
。确保支持正确的方法。您可以尝试使用POST
webClient.UploadFile(webAddress , "POST", @"C:\d\1.xml");