Question

I am trying to access and modify the properties 'creationdate' and 'lastmodified' of a file that I have previously uploaded to a webdav URL. I am getting the response 'HTTP/1.1 424 Failed Dependency' which I interpret as 'The request failed due to failure of a previous request' according to https://www.rfc-editor.org/rfc/rfc4918.

I am lost as to what previous request is failing here, for when I run the code I don't get any error on it. Here is the code:

FileInfo^ myfI=gcnew FileInfo(myfilePath);
String^ mytime=myfI->LastWriteTimeUtc.ToFileTimeUtc().ToString();
String^ strBody = "<?xml version=\"1.0\"?>"
            + "<d:propertyupdate xmlns:d=\"DAV:\">"
            + "<d:set>"
            + "<d:prop>"
            + "<creationdate>" + myfI->CreationTimeUtc.ToFileTimeUtc().ToString() + "</creationdate>"
            + "</d:prop>"
            + "<d:prop>"
            + "<lastmodified>" + mytime + "</lastmodified>"
            + "</d:prop>"
            + "</d:set>"
            + "</d:propertyupdate>";

array<Byte>^ mybytes= Encoding::UTF8->GetBytes(strBody);

String^ responseresult="";
String^ filename= myfI->Name;
System::Net::HttpWebRequest^ httpPutRequest = (System::Net::HttpWebRequest^)System::Net::WebRequest::Create(this->myURL + destinationpath+ "/" + filename);
    httpPutRequest->Credentials = gcnew NetworkCredential(this->myUserName, this->myPassword);
    httpPutRequest->PreAuthenticate = true;
    httpPutRequest->Method = L"PROPPATCH";
httpPutRequest->ContentType = "text/xml";
httpPutRequest->ContentLength = mybytes->Length;
Stream^ requestStream = httpPutRequest->GetRequestStream();
requestStream->Write(mybytes,0,mybytes->Length);
requestStream->Close();

HttpWebResponse^ httpPutResponse = (HttpWebResponse^)httpPutRequest->GetResponse();
responseresult=httpPutResponse->StatusDescription;
HttpStatusCode mycode=httpPutResponse->StatusCode;
Stream^ myresponse=httpPutResponse->GetResponseStream();
StreamReader^ myr=gcnew StreamReader(myresponse);
String^ res=myr->ReadToEnd();

I have tried with only one property as well and have the same response.

Any advise, please?

Was it helpful?

Solution

It's important to echo the entire response. Failed dependency will be emitted in a following case:

  1. You are doing a PROPPATCH to update more than 1 property
  2. One of those properties fails (for example 403 Forbidden)
  3. The other properties now will automatically get 424 Failed Dependency, because the PROPATCH must either entirely succeed, or entirely fail.

My guess is that your server does not allow you to update one or more of those properties. {DAV:}lastmodified in particular is in general a protected, and thus a read-only property that you are never allowed to change. It depends on the server if they do or do not actually allow you to do that, but in general it should fail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top