Using Delphi 2007, Using InDy 10, Using TIdWebDAV, service webdav.yandex.ru, I want to publish a file, but I get an error authorization
procedure TForm2.Button1Click(Sender: TObject);
Var
s, r: TStringStream;
begin
s := TStringStream.Create('<propertyupdate xmlns="DAV:">' + sLineBreak +
'<set>' + sLineBreak +
'<prop>' + sLineBreak +
'<public_url xmlns="urn:yandex:disk:meta">true</public_url>' + sLineBreak +
'</prop>' + sLineBreak +
'</set>' + sLineBreak +
'</propertyupdate>');
r := TStringStream.Create('');
try
//fill params
IdWebDAV1.URL.Password := '*****';
IdWebDAV1.URL.Username := '***@yandex.ru';
IdWebDAV1.URL.Port := '80';
IdWebDAV1.URL.URI := '/tst/readme.txt';
IdWebDAV1.URL.Host := 'webdav.yandex.ru';
IdWebDAV1.URL.Protocol := 'PROPFIND';
//fill OAuth ID
IdWebDAV1.Request.CustomHeaders.Add('Authorization: OAuth c953e33d6ec14895aa776f55145e73b5');
IdWebDAV1.Put('https://webdav.yandex.ru/', s, r);
//result
Memo1.Lines.Text := r.DataString;
finally
s.Free;
r.Free;
end;
end;
I get an ERROR: HTTP/1.1 401 Unauthorized.
You are not using
TIdWebDAVcorrectly. You should be using itsDAVPropPatch()method instead of itsPut()method when postingpropertyupdateXML, and you should not be filling theURIproperty manually at all.Try this instead: