启用协议 HTTP2 Delphi 11

Enable Protocol HTTP2 Delphi 11

如何启用 HTTP2 Delphi11? 我一直在尝试使用代码,但没有用

NetHTTPClient1.ProtocolVersion := 'HTTP_2_0';

这应该有效:

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;

编辑:2021-09-23 12:23:将代码更新为您在评论中提出的问题