none
WebRequest GetResponseAsync 405 RRS feed

  • Question

  • Hi, i use a webdav console application and i have an error in GetResponseAsync function.

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

    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();
            }

    Wednesday, January 23, 2019 8:43 AM

All replies

  • Hi Karim Samir,

    Thank you for posting here.

    In order to solve your problem better, please share the code about the GetResponseAsync function.

    We are waiting for your update.

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 24, 2019 7:20 AM
    Moderator