-11
我在Delphi 7中使用的Dropbox API V2 Windows桌面軟件開發。 我的代碼不起作用。請爲我提供一個正確的Delphi代碼! 謝謝!德爾福的Dropbox API第2版文件上傳
我的代碼片段:
procedure TDropbox.Upload(SourceFileName: String; DropBoxFileName: String; FTimeout: Integer = 5000);
const
FDropBoxAppAccessToken = 'xxxxxxxxxxxxxxxxxxxx';
var
FHTTPS: TIdHTTP;
FStream: TFileStream;
FDropBoxResponseCode: Integer;
FHTTPResponse: String;
begin
FHTTPRequestURL := 'https://api-content.dropbox.com/2/files/upload';
FStream := TFileStream.Create(SourceFileName, fmOpenRead);
FStream.Position := 0;
FHTTPS := TIdHTTP.Create(nil);
FHTTPS.ConnectTimeout := FTimeout;
FDropBoxResponseCode := 0;
FHTTPResponse := '';
params := TStringList.Create;
arg := 'Dropbox-API-Arg:{"path:"' + FDropBoxBaseAppPath + DropBoxFileName + '}';
try
FHTTPS.Request.CustomHeaders.Add('Authorization:Bearer ' + FDropBoxAppAccessToken);
FHTTPS.Request.CustomHeaders.AddStrings := '(Dropbox-API-Arg:{"path:"' + FDropBoxBaseAppPath + DropBoxFileName + '}');
FHTTPS.Request.CustomHeaders.Values[arg];
FHTTPS.Request.ContentType := 'application/octet-stream';
FHTTPS.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(FHTTPS);
FHTTPResponse := FHTTPS.Post(FHTTPRequestURL, FStream);
except on E: Exception do
begin
end;
end;
Dropbox的服務器總是說:
400錯誤的請求,源文件是存在的。
請幫幫忙!
請妥善格式化你的代碼。明確提出代碼和預期行爲。目前你的代碼很難解釋。 –
400錯誤請求錯誤意味着HTTP後以某種方式畸形,所述服務器不接受。 – Fero
是不是你的'(Dropbox的-API精氨酸:..'缺少一個右 ')' ** **裏面的字符串?實際上,關閉')'看起來像一個語法錯誤。 – MartynA