【发布时间】:2017-04-24 11:41:20
【问题描述】:
我想使用 HTTP POST 方法发送位图图像。如何将其发送到 URL?
我正在使用 Indy 10 和 Delphi 10.1。在一个过程中,我创建了一个包含所有参数值的TStringList,但我不知道如何传递位图数据。
这是我的代码:
procedure TuDm_Athlos.AddComandaInsertLogo(workList: TStringList;
imageStream: TStream);
var
image : TBitmap;
begin
try
image := TBitmap.Create;
imageStream := TStream.Create;
image.LoadFromFile('D:\\COFEE.BMP');
image.SaveToStream(imageStream);
workList.Add('db=titles');
workList.Add('line_1=');
worklist.Add('line_2=');
workList.Add('line_3=');
workList.Add('line_4=');
workList.Add('line_5=');
workList.Add('line_6=');
workList.Add('store=&DB=PRN_UDG');
workList.Add('code=1');
workList.Add('width=' + IntToStr(image.Width));
workList.Add('height=' + IntToStr(image.Height));
workList.Add('length=576');
workList.Add('store=');
finally
FreeAndNil(imageStream);
end;
end;
function TuDm_Athlos.InsertLogo(imageStream: TStream;
isFullResponse: Boolean): Boolean;
var
StrResult : UTF8String;
workList : TStringList;
ContentStream : TStream;
image : TBitmap;
begin
//Setup;
Result := False;
try
try
workList := TStringList.Create;
ContentStream := TStream.Create;
image := TBitmap.Create;
image.LoadFromStream(imageStream);
AddComandaInsertLogo(workList,imageStream);
AddComandaSummarize(workList, False);
StrResult := IdHTTP1.Post(printerURL + 'db_status.xml?',workList);
ContentStream := StringToStream(strResult);
Result := XmlReadCommanda(imageStream); //XmlReadComanda(ContentStream);
except
on e : Exception do begin
//DisconnectHttpClient;
//raise Exception.Create(TranslateHttpError(e.Message));
end;
end;
finally
FreeAndNil(workList);
FreeAndNil(image);
ContentStream.Free;
end;
end;
【问题讨论】:
标签: delphi http-post indy indy10 delphi-10.1-berlin