delphitcpdelphi-10.2-tokyosysinternals

THttpClient is not closing connection in Delphi


My software includes the function below for posting to URL. I'm using Sysinternals TCPView to see the connection. The connection is not closing after posting to URL. How should I change the code for immediate connection close?

function PostURL(const AURL: string; Parameters: TStrings): string;
var
  HttpClient: THttpClient;
  HttpResponse: IHttpResponse;
begin
  HttpClient := THTTPClient.Create;
  try
    HttpClient.ConnectionTimeout:=3000;
    HttpClient.ResponseTimeout:=3000;
    HttpResponse := HttpClient.Post(AURL, Parameters, nil, TEncoding.UTF8);
    Result := HttpResponse.ContentAsString();
  finally
    HttpClient.Free;
  end;
end;

Solution

  • what about the following

     HttpClient.SetRequestHeader('Connection', 'close');