J'ai réussi à créer un document Bluemix Cloudant et j'ai mis une pièce jointe à ce document avec un programme Delphi. Je suis également en mesure de récupérer cette pièce jointe via un fichier BAT, mais je voudrais le faire avec Delphi 2009. Je reçois une réponse HTTP/1.1 200 OK, je ne sais pas où obtenir la pièce jointe Le code :Comment puis-je récupérer une pièce jointe dans une base de données Cloudant avec Delphi?
program httpsGet;
{$R *.res}
{$APPTYPE CONSOLE}
uses
IdHTTP, IdSSLOpenSSL, IdGlobal, SysUtils,IniFiles, Classes;
var
HTTP: TIdHTTP;
RequestBody: TStream;
ResponseBody: string;
LHandler: TIdSSLIOHandlerSocketOpenSSL;
json: string;
F: textfile;
s: string;
id,rev: string;
Dir,user,password,mapp,butik: string;
IniFile: TInifile;
a,i,x,Antdocs: integer;
begin
// Read ini-file and get user/password
Dir:=ExtractFilePath(ParamStr(0));
IniFile:=TIniFile.create(Dir + 'Credentials.ini');
user:=IniFile.Readstring('Credentials','User','');
password:=IniFile.Readstring('Credentials','Password','');
IniFile.Destroy;
id:='02d42fc7c5966b2ab7d27a3c9942a77e';
rev:='2-904b6ca2f8883e35b931d138acc969c6';
json:='{ "selector": {"_id":"' + id + '"}, "fields": "_attachment" } ';
HTTP := TIdHTTP.Create;
try
try
RequestBody := TStringStream.Create(json, TEncoding.UTF8);
LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
try
WriteLn(' RequestBody: ' + json);
WriteLn('');
HTTP.Request.BasicAuthentication:= true;
HTTP.ConnectTimeout:= 10000;
HTTP.Request.UserName := user;
HTTP.Request.Password := password;
HTTP.Request.Accept := 'application/json';
HTTP.Request.ContentType := 'application/json';
HTTP.IOHandler:=LHandler;
ResponseBody := HTTP.Get('https://' + user + '.cloudant.com/pmu/');
WriteLn(' ResponseBody: ' + ResponseBody);
WriteLn(HTTP.ResponseText);
finally
RequestBody.Free;
Lhandler.Free;
end;
except
on E: EIdHTTPProtocolException do
begin
WriteLn(E.Message);
WriteLn(E.ErrorMessage);
end;
on E: Exception do
begin
WriteLn(E.Message);
end;
end;
finally
HTTP.Free;
end;
ReadLn;
ReportMemoryLeaksOnShutdown := True;
end.
sortie est:
RequestBody: { "sélecteur": { "_id": "02d42fc7c5966b2ab7d27a3c9942a77e"}, "champs": "_attachment"} responseBody: { "update_seq" : "331-g1AAAAPHeJzLYWBgEMhgTmFQSUlKzi9KdUhJMjTQS8rVTU7WLc3WNTDUS87JL01JzCvRy0styQGqZkpkSOL ___ 9_ViIHSJ8yQh9-bUkCQDJJHqxTAFWnGQGdCiCd-mCdoqg6jQjoNADptAfr5CTNl0k OIK3-YK3iqJZaEtAZANIZD9YpSZpHE0A688E6hUjzaAFIZz1YJz9pHs1jAZIMDUAKqLsfI4QJeBaiewJE9_ysRHlU3ebE6F4A0b0-K1GaJE9DdG-A6N6flahIjscPQLSfJzWWIbovQHTfJzWmIbofQHS_z0rkJcPjHyC6QekzCwCYMTXF », "nom_base": "pmu", "tailles": { "fichier": 9.239.940, "externe": 2.290.914, "active": 2.392.413}, "purge_seq": 0, "autre" : {"taille_données": 2290914}, "doc_del_count": 130, "doc_count": 2, "taille_disque": 9239940, "version_format_disque": 6, "taille_données": 2392413, "compact_running": false, "instance_start_time": " 0 "} HTTP/1.1 200 OK
Je m'attendais à ce que la pièce jointe soit le ResponseBody. Le document Cloudant se présente comme suit: Doc layout for specified id
Quelqu'un peut-il me donner un indice? Cordialement