Trying to create a file on remote machine using c#.net and webdav RRS feed

  • Question

  • User840719532 posted

    Here is my code:

    string szUsername = "c0relynx";
    string szPassword = "c0relynx";
    string szURL1 ="http://xx.xx.xx.xx/webdav/foobar1.txt";
    string szContent = String.Format(@"Date/Time: {0} {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());
    HttpWebRequest httpPutRequest = (HttpWebRequest)WebRequest.Create(szURL1);
    httpPutRequest.Credentials = new NetworkCredential(szUsername, szPassword);
    httpPutRequest.PreAuthenticate = true;
    httpPutRequest.Method = @"PUT";
    httpPutRequest.Headers.Add(@"Overwrite", @"T");
    httpPutRequest.ContentLength = szContent.Length;
    httpPutRequest.SendChunked = true;
    httpPutRequest.KeepAlive = true;
    Stream requestStream = httpPutRequest.GetRequestStream();
    requestStream.Write(Encoding.UTF8.GetBytes((string)szContent), 0, szContent.Length);
    HttpWebResponse httpPutResponse = (HttpWebResponse)httpPutRequest.GetResponse();

    when the last line is executed I get the exception "The remote server returned an error: (405) Method Not Allowed."

    Any suggestions on where I have gone wrong ?



    Monday, February 1, 2016 8:53 AM


All replies