【发布时间】:2017-08-18 15:46:02
【问题描述】:
我已成功创建了一个 Bluemix Cloudant 文档,并使用 Delphi 程序将附件放入该文档。我还可以通过 BAT 文件检索该附件,但我想使用 Delphi 2009 来完成。我得到了 一个 HTTP/1.1 200 OK 响应,我不知道从哪里得到附件 代码:
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.
输出是:
RequestBody: { "selector": {"_id":"02d42fc7c5966b2ab7d27a3c9942a77e"}, “字段”:“_attachment”}响应体: { “update_seq”: “331-g1AAAAPHeJzLYWBgEMhgTmFQSUlKzi9KdUhJMjTQS8rVTU7WLc3WNTDUS87JL01JzCvRy0styQGqZkpkSOL ___ 9_ViIHSJ8yQh9-bUkCQDJJHqxTAFWnGQGdCiCd-mCdoqg6jQjoNADptAfr5CTNl0kOIK3-YK3iqJZaEtAZANIZD9YpSZpHE0A688E6hUjzaAFIZz1YJz9pHs1jAZIMDUAKqLsfI4QJeBaiewJE9_ysRHlU3ebE6F4A0b0-K1GaJE9DdG-A6N6flahIjscPQLSfJzWWIbovQHTfJzWmIbofQHS_z0rkJcPjHyC6QekzCwCYMTXF”, “DB_NAME”: “PMU”, “尺寸”:{ “文件”:9239940, “外部”:2290914, “活性”: 2392413},"purge_seq":0,"other":{"data_size":2290914},"doc_del_count":130,"doc_count":2,"disk_size":9239940,"disk_format_version":6,"data_size":2392413 ,"compact_running":false,"instance_start_time":"0"} HTTP/1.1 200 正常
我预计附件是 ResponseBody。 Cloudant 文档如下所示: Doc layout for specified id
谁能给我一个提示? 问候
【问题讨论】:
标签: delphi https ibm-cloud indy cloudant