[fpc-pascal] Prorammatically sending file using HTTP POST?
Bo Berglund
bo.berglund at gmail.com
Wed Apr 4 17:50:40 CEST 2018
On Wed, 4 Apr 2018 17:09:49 +0200 (CEST), Michael Van Canneyt
<michael at freepascal.org> wrote:
>I don't know what a 'good example' is for you, but the code in
>
>https://stackoverflow.com/questions/27257577/indy-mime-decoding-of-multipart-form-data-requests-returns-trailing-cr-lf
>
>Is quite understandable.
I found this example too, but it seems to be dealing with *server*
side stuff...
I am trying to create a *client* function which will send a POST
command like a browser would when I click the submit button on the
simple form I showed the source for.
It works fine if I use the web browser to connect and load the form,
then select the file and finally hit the submit button.
But since I already have all of the other device config items inside
an FPC program I wanted the firmware upload to also be part of it...
This is how far I have gotten with the UploadFirmware method:
function TConfigCommHandler.UploadFirmware(FileName: string; URL:
string): boolean;
var
HTTP: TIdHTTP;
Src: TIdMultipartFormDataStream;
begin
Result := false;
if not FileExists(FileName) then exit;
HTTP := TIdHTTP.Create;
Src := TIdMultipartFormDataStream.Create;
try
Src.AddFormField('?',?);
Src.AddFile(FileName,'?');
try
HTTP.Post(URL, Src, ?);
Result := true;
except
on E: Exception do
FLastError := 'Exception: ' + E.Message;
end;
finally
Src.Free;;
HTTP.Free;
end;
end;
It is all about formulating the correct parameters towards the
HTTP.Post function.
--
Bo Berglund
Developer in Sweden
More information about the fpc-pascal
mailing list