* * *

Author Topic: httppost Robbanux[SOLVED by Myself ] Very simpel solution...  (Read 2538 times)


  • Full Member
  • ***
  • Posts: 232
  • Love my Wife, My Kids and Lazarus/Freepascal.
httppost Robbanux[SOLVED by Myself ] Very simpel solution...
« on: February 05, 2017, 03:57:51 am »
I figured it out.This is the way to do it. :)

uses fphttpclient;

procedure TForm1.Button1Click(Sender: TObject);
  Respo: TStringStream;
  S : String;//server answer
text: String;//my send string

text:='This text will be sent to the upload server,bla bla bla';//Works great with ssl

  With TFPHttpClient.Create(Nil) do

      showmessage('S='+S);//Check what answer you get from server and voila


Many thanks to the Lazarus/Freepascal team for fphttpclient . Lazarus/Freepascal rules.
« Last Edit: February 06, 2017, 10:21:03 pm by Bob the Swede »


  • Guest
Re: httppost !!!
« Reply #1 on: February 05, 2017, 08:45:56 am »
EDIT: Actually, if edtSourceFile.Text is a filename then you are correct. Have you a server ready to receive?


Looks like you are trying to use this method:
Code: Pascal  [Select]
  1. procedure TFPCustomHTTPClient.FileFormPost(
  2.   const AURL, AFieldName,  
  3.   AFileName: string;
  4.   const Response: TStream);  
Except you want to use this:
Code: Pascal  [Select]
  1. procedure TFPCustomHTTPClient.FileFormPost(
  2.   const AURL: string;
  3.   FormData: TStrings;
  4.   AFieldName, AFileName: string;
  5.   const Response: TStream);      
So, you code should be (if edtSourceFile is a TStrings)
Code: Pascal  [Select]
  1. FileFormPost('http://example.com/upload.php', edtSourceFile, 'PostFilenameParam',Respo);

The fieldparam is used by the server to identify the edtSourceFile data sent. A server expecting this data must be available.

Another option is to use a HTTP PUT for a file upload, but again, the server must be expecting your data.
« Last Edit: February 05, 2017, 08:49:34 am by Geepster »


  • Hero Member
  • *****
  • Posts: 7901
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: httppost example needed!!!It's also ssl server i'm afraid
« Reply #2 on: February 06, 2017, 10:52:44 am »
the error message says: No data!! :o this is easy in PHP why not in pascal?
This is just as easy but requires you to understand how to use it correctly, just as when you learn it using PHP.
  • AURL is clear, the target URL where the file will be POST-ed to
  • AFieldName is the name attribute as if you write in HTML:
    <input type="file" name="this is AFieldName" />
  • AFileName is the path to the file you want to upload where your app will run from, e.g.: /what/ever/this/shit/is.jpg
  • Response is any TStream descendant instance that will hold the HTTP response body after you execute the function
  • FormData, if exists, is other fields you would like to send since multipart/form-data also allows more than just a file to be sent



Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus