Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your code is close. You are only sending your file field but not your text fields. To do all three, try this instead:</p> <pre><code>function HttpPostFile(const URL, InputText1FieldName, InputText1, InputText2FieldName, InputText2, InputFileFieldName, InputFileName: string; InputFileData: TStream; ResultData: TStrings): Boolean; var HTTP: THTTPSend; Bound: string; begin Bound := IntToHex(Random(MaxInt), 8) + '_Synapse_boundary'; HTTP := THTTPSend.Create; try WriteStrToStream(HTTP.Document, '--' + Bound + CRLF + 'Content-Disposition: form-data; name=' + AnsiQuotedStr(InputText1FieldName, '"') + CRLF + 'Content-Type: text/plain' + CRLF + CRLF); WriteStrToStream(HTTP.Document, InputText1); WriteStrToStream(HTTP.Document, CRLF + '--' + Bound + CRLF + 'Content-Disposition: form-data; name=' + AnsiQuotedStr(InputText2FieldName, '"') + CRLF + 'Content-Type: text/plain' + CRLF + CRLF); WriteStrToStream(HTTP.Document, InputText2); WriteStrToStream(HTTP.Document, CRLF + '--' + Bound + CRLF + 'Content-Disposition: form-data; name=' + AnsiQuotedStr(InputFileFieldName, '"') + ';' + CRLF + #9'filename=' + AnsiQuotedStr(InputFileName, '"') + CRLF + 'Content-Type: application/octet-string' + CRLF + CRLF); HTTP.Document.CopyFrom(InputFileData, 0); WriteStrToStream(HTTP.Document, CRLF + '--' + Bound + '--' + CRLF); HTTP.MimeType := 'multipart/form-data; boundary=' + Bound; Result := HTTP.HTTPMethod('POST', URL); if Result then ResultData.LoadFromStream(HTTP.Document); finally HTTP.Free; end; end; </code></pre> <p>If you switch to Indy, you can use its <code>TIdMultipartFormDataStream</code> class:</p> <pre><code>function HttpPostFile(const URL, InputText1FieldName, InputText1, InputText2FieldName, InputText2, InputFileFieldName, InputFileName: string; InputFileData: TStream; ResultData: TStrings): Boolean; var HTTP: TIdHTTP; Input: TIdMultipartFormDataStream; Output: TMemoryStream; begin Result := False; try Output := TMemoryStream.Create; try HTTP := TIdHTTP.Create; try Input := TIdMultipartFormDataStream.Create; try Input.AddFormField(InputText1FieldName, InputText1); Input.AddFormField(InputText2FieldName, InputText2); Input.AddFormField(InputFileFieldName, 'application/octet-stream', '', InputFileData, InputFileName); HTTP.Post(URL, Input, Output); finally Input.Free; end; finally HTTP.Free; end; Output.Position := 0; ResultData.LoadFromStream(Output); Result := True; finally Output.Free; end; except end; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload