实现附件的上传:需要使用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;
|
请发表评论