我使用webdav控制台应用程序,并且GetResponseAsync函数出现错误。
错误:远程服务器返回错误:(405)不允许的方法
public async Task GetFolder(string url)
{
var request = GetWebRequest(url, "PROPFIND");
string query = @"<?xml version=""1.0"" encoding=""utf-8""?> <propfind xmlns=""DAV:""> <propname/> </propfind>";
var bytes = Encoding.UTF8.GetBytes((string)query);
request.ContentLength = bytes.Length;
request.ContentType = @"application/xml; charset=""utf-8""";
request.Headers.Add("Depth", "1");
var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
var response = await request.GetResponseAsync();
var responseStream = response.GetResponseStream();
var reader = new XmlTextReader(responseStream);
string output = "";
while (reader.Read())
{
if (reader.Value.Contains("http"))
{
output += reader.Value.ToString() + "\n";
}
}
Console.WriteLine(output);
reader.Close();
responseStream.Close();
response.Close();
}