Recent

Author Topic: [SOLVED] HTTPS SimpleFormPost with TFPHTTPClient : Headers Issue  (Read 4179 times)

tudi_x

  • Hero Member
  • *****
  • Posts: 531
hi All,
i am trying to make a POST request with custom headers.
the code is the below and attached.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   HTTPS: TFPHTTPClient;
  4.   POSTBody: TStringList;
  5.   DebugURL: string = 'https://requestb.in/1bqcc6f1';
  6.   err: string;
  7.  
  8. begin
  9.   POSTBody := TStringList.Create;
  10.   POSTBody.Append('<share>');
  11.   POSTBody.Append('</share>');
  12.  
  13.   try
  14.     HTTPS := TFPHTTPClient.Create(nil);
  15.  
  16.     HTTPS.AddHeader('Authorization', 'Bearer ' + 'TOKEN xxxxxxx');
  17.     HTTPS.AddHeader('x-li-format', 'json');
  18.     HTTPS.AddHeader('Content-Type', 'application/json');
  19.  
  20.     err := HTTPS.SimpleFormPost(DebugURL, POSTBody);
  21.     Memo1.Append(err);
  22.  
  23.   finally
  24.     FreeAndNil(HTTPS);
  25.     FreeAndNil(POSTBody);
  26.   end;
  27. end;          
  28.  
  29.  

it looks like the headers are not arriving to the web site - please see screen capture.

please advise what i am missing.

thank you!

using Lazarus 1.6.4 64 bit on Windows 7 and https://indy.fulgan.com/SSL/openssl-1.0.2l-x64_86-win64.zip
« Last Edit: July 15, 2017, 01:49:14 pm by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

tudi_x

  • Hero Member
  • *****
  • Posts: 531
Re: HTTPS SimpleFormPost with TFPHTTPClient : Headers Issue
« Reply #1 on: July 15, 2017, 01:48:50 pm »
It looks it is working with
 
Code: Pascal  [Select][+][-]
  1. err := HTTPS.FormPost(DebugURL, POSTBody);
  2.  

Lazarus 2.0.2 64b on Debian LXDE 10

Leledumbo

  • Hero Member
  • *****
  • Posts: 8420
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: [SOLVED] HTTPS SimpleFormPost with TFPHTTPClient : Headers Issue
« Reply #2 on: July 15, 2017, 06:22:19 pm »
SimpleFormPost is a class method, it doesn't read your AddHeader at all. That method simple creates volatile instance of TFPHTTPClient and call FormPost using URL and Body parameters that you give then return the result.

 

TinyPortal © 2005-2018