我正在尝试在OneDrive上创建文件夹。这个代码适用于XE8 + Indy 10.但是对于Indy 9和Delphi 7两次,我有三次: “EIdHTTPProtocolException并显示消息”未找到http / 1.1 404“。无论如何都会创建该文件夹。
有没有办法避免Indy 9的异常?我不能在Delphi 7中使用Indy 10因为规格。
procedure OneDriveCreateFolderTest;
const
URL = 'https://api.onedrive.com/v1.0/drive/root::/children';
var
IdHttp: TIdHttp;
IdSSLIOHandlerSocket: TIdSSLIOHandlerSocket; // XE8 => TIdSSLIOHandlerSocketOpenSSL
Stream: TStringStream;
begin
IdHttp := TidHTTP.Create(nil);
try
IdHttp.HandleRedirects := True;
IdSSLIOHandlerSocket := TIdSSLIOHandlerSocket.Create(IdHttp);
IdSSLIOHandlerSocket.SSLOptions.Method := sslvTLSv1;
IdHttp.IOHandler := IdSSLIOHandlerSocket;
IdHttp.Request.CustomHeaders.FoldLength := MaxInt;
IdHttp.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + FAccessToken;
IdHttp.Request.BasicAuthentication := False;
IdHttp.Request.ContentType := 'application/json';
Stream := TStringStream.Create('{ "name": "TestDir", "folder": { } }');
try
IdHttp.Post(URL, Stream);
finally
Stream.Free;
end;
finally
IdHttp.Free;
end;
end;