[Solved]Post request fphttpclient lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- stonefull · 2023-09-07 13:02 How to create a post request in fphttpclient using x-www-form- urlencoded? I did not find anything about this in https://wiki.lazarus.freepascal.org/fphttpclient. ---------------------------------------------------------------------- delphius · 2023-09-07 13:34 Quote from: stonefull on September 07, 2023, 03:02:10 pmHow to create a post request in fphttpclient using x-www-form-urlencoded? I did not find anything about this in https://wiki.lazarus.freepascal.org/fphttpclient. May be official examples will help? ---------------------------------------------------------------------- stonefull · 2023-09-07 15:11 Nothing. Sorry. I think I am going create a new route in API that accepts application/json ---------------------------------------------------------------------- TRon · 2023-09-08 04:10 Quote from: stonefull on September 07, 2023, 05:11:38 pmNothing. Sorry. I think I am going create a new route in API that accepts application/json What do you mean by nothing ? The example from the link uses formpost which effectively adds the x-www-form-urlencoded header so that you do not have to do that manually. :confused: ---------------------------------------------------------------------- stonefull · 2023-09-08 14:29 Quote from: TRon on September 08, 2023, 06:10:27 amQuote from: stonefull on September 07, 2023, 05:11:38 pmNothing. Sorry. I think I am going create a new route in API that accepts application/json What do you mean by nothing ? The example from the link uses formpost which effectively adds the x-www-form-urlencoded header so that you do not have to do that manually. :confused: I was not understanding how to pass params in a TStrings. Now I resolved: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  params: TStrings;  Response: TStringStream;  httpClient: TFPHttpClient;begin  Response := TStringStream.Create('');  httpClient := TFPHttpClient.Create(Nil);   params := TStringList.create;  params.add('param=value');  httpClient.FormPost('http://address.com', params, Response);  // ...end;  Thanks a lot ---------------------------------------------------------------------- TRon · 2023-09-08 23:08 Quote from: stonefull on September 08, 2023, 04:29:10 pmI was not understanding how to pass params in a TStrings. Now I resolved: Ah, ok. That was not entirely clear from your response. It could have been solved in a jiffy so following is for demonstration purpose: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program poster; {$mode objfpc}{$H+} uses  classes, fphttpclient, opensslsockets; procedure dopost;var  Client   : TFPHTTPClient;  Response : TStringList;  FormData : TStringList;  URL      : string = 'https://httpbin.org/post';begin  Response := TStringList.Create;  FormData := TStringList.Create;  Client   := TFPHTTPClient.Create(nil);  try    // Create some random form data    // The numbers in front are for ordering purpose only    Formdata.Values['1 it']    := 'is also possible';    Formdata.Values['2 to']    := 'assign parameters';    Formdata.Values['3 using'] := 'the values property';    Formdata.Values['4 of']    := 'a stringlist';     // set user agent identifier:    // not required for this API. For demonstration purpose only.    Client.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');     // accept json return value(s):    // not required for this API. For demonstration purpose only.    Client.AddHeader('Accept', 'application/json');     // Post request  Client.FormPost(URL, FormData, Response);     // print result:    Writeln(Response.Text);   finally    Response.Free;    FormData.Free;    Client.Free;  end;end; begin  dopost;end.  Which results in: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {  "args": {},  "data": "",  "files": {},  "form": {    "1 it": "is also possible",    "2 to": "assign parameters",    "3 using": "the values property",    "4 of": "a stringlist"  },  "headers": {    "Accept": "application/json",    "Content-Length": "110",    "Content-Type": "application/x-www-form-urlencoded",    "Host": "httpbin.org",    "User-Agent": "Mozilla/5.0 (compatible; fpweb)",    "X-Amzn-Trace-Id": "Root=1-64fba797-5c75720b4f39586f1e723270"  },  "json": null,  "origin": "xxx.xxx.xxx.xxx",  "url": "https://httpbin.org/post"}