delphi请求http接口并上传附件

2017-07-26 21:19:03来源:cnblogs.com作者:坤霸天下人点击

分享

实现附件的上传:需要使用TIdMultiPartFormDataStream控件,

uses  

     IdMultipartFormData;

  

例子:

procedure TClientForm.Button42Click(Sender: TObject);
var paramStream: TIdMultiPartFormDataStream;
vResponse: TStringStream;
filename, vres: string;
vList: TStringList;
jsonstr: string;
begin
paramStream := TIdMultiPartFormDataStream.Create;
vResponse := TStringStream.Create('');
vList := TStringList.Create;

//传递普通参数
paramStream.AddFormField('fun', 'ADD_ATTA');
paramStream.AddFormField('PROCESS_ID', '4');
paramStream.AddFormField('user_id', '2');
paramStream.AddFormField('name', '2');
paramStream.AddFormField('attachment_memo', '2');
paramStream.AddFormField('filename', 'C:/1.doc');

//上传文件需要用的addFile属性
filename := 'C:/1.doc';//文件路径
paramStream.AddFile('file', filename, GetMIMETypeFromFile(filename));
IdHTTP1.Post('http://localhost:8089/ENGINEER?', paramStream, vResponse);
vres := (vResponse.DataString); //Utf8ToAnsi
Memo1.Text := vres;
// ShowMessage(vres);
end;

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台