Cannot reuse TFPHTTPClient. lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- ExSystem · 2017-02-25 07:55 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 project1; Uses  fphttpclient,  Classes,  SysUtils; Var  FHttpClient: TFPHTTPClient;  FServerUri: String;  Controller: String;  Action: String;  mResponse: String;Begin  Try    Try      FServerUri := 'http://www.baidu.com/';      Controller := 'aa';      Action := 'bb';       FHttpClient := TFPHTTPClient.Create(Nil);      FHttpClient.RequestBody := TStringStream.Create('{"Revisions":[]}');    FHttpClient.AddHeader('Content-Type', 'text/json');      mResponse := FHttpClient.Post(Format('%s%s/%s', [FServerUri, Controller, Action]));      FHttpClient.RequestBody.Free();      FHttpClient.RequestBody := Nil;      WriteLn('#1: ', mResponse);     Action := 'cc';      mResponse := FHttpClient.FormPost(Format('%s%s/%s', [FServerUri, Controller, Action]), 'Page=1');      WriteLn('#2: ', mResponse);    Except      On e: Exception Do      Begin        WriteLn('######### ', E.Message);        ReadLn();      End;    End;  Finally    WriteLn('FINISH!');    ReadLn();    FHttpClient.Free();    FHttpClient := Nil;  End;End.  As the code mentioned above, the second request cannot be finished and the program hung for a long time and exited. Why? Thanks. I'm using FPC3.1.1/CodeTyphon 6.0/Windows10 (64bit) ---------------------------------------------------------------------- balazsszekely · 2017-02-25 09:22 Just clear the request headers between the two request: 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   //... WriteLn('#1: ', mResponse); FHttpClient.RequestHeaders.Clear; //<-- add this line Action := 'cc';    //... ---------------------------------------------------------------------- ExSystem · 2017-02-25 12:05 Quote from: GetMem on February 25, 2017, 10:22:06 amJust clear the request headers between the two request: 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   //... WriteLn('#1: ', mResponse); FHttpClient.RequestHeaders.Clear; //<-- add this line Action := 'cc';    //... Quite confused. Header 'Content-Type' should be replaced by FormPost method, why Clear is required? Will it impact my cookies settings (eg. the 'login' thing) produced by the first request? 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 procedure TFPCustomHTTPClient.FormPost(const URL, FormData: string;  const Response: TStream); begin  RequestBody:=TStringStream.Create(FormData);  try    AddHeader('Content-Type','application/x-www-form-urlencoded');    Post(URL,Response);  finally    RequestBody.Free;    RequestBody:=Nil;  end;end; BTW: How to stepping in the source code of TFPHTTPClient when debugging?...Really recompile it with debug info? ---------------------------------------------------------------------- balazsszekely · 2017-02-25 14:48 QuoteQuite confused. Header 'Content-Type' should be replaced by FormPost method, why Clear is required? Will it impact my cookies settings (eg. the 'login' thing) produced by the first request?Well apparently it does not get replaced by FormPost. I did not study how FormPost works internally, but you can find out by debugging the code. QuoteTW: How to stepping in the source code of TFPHTTPClient when debugging?...Really recompile it with debug info?Ideally you should recompile FPC with debug info, however in this particular case there is a shortcut. Just copy fphttpclient.pp from $(FPCDir)\source\packages\fcl-web\src\base\  to your project folder and you're good to go.