Home > OS >  Enable Protocol HTTP2 Delphi 11
Enable Protocol HTTP2 Delphi 11

Time:09-24

How to enable HTTP2 Delphi 11 ? I has been try with code, but not work

NetHTTPClient1.ProtocolVersion := 'HTTP_2_0';

CodePudding user response:

This should work:

implementation

uses
  System.Net.HttpClient;

procedure DoSomeHTTPThings;
var
  http: THTTPClient;
  httpresponse: IHTTPResponse;
  stringstream: TSTringStream;
begin
  http := THTTPClient.Create;
  stringstream := TStringStream.Create;
  try
    http.ProtocolVersion := THTTPProtocolVersion.HTTP_2_0;
    httpresponse := http.Get('http://exampleurl.com', stringstream);
    case httpresponse.Version of
      THTTPProtocolVersion.UNKNOWN_HTTP: ;
      THTTPProtocolVersion.HTTP_1_0: ;
      THTTPProtocolVersion.HTTP_1_1: ;
      THTTPProtocolVersion.HTTP_2_0: ;
    end;
  finally
    stringstream.Free;
    http.Free;
  end;
end;

Edit: 2021-09-23 12:23: Updated the code to your question in comment

  • Related