0

如何启用 HTTP2 Delphi 11?我一直在尝试使用代码,但无法正常工作

NetHTTPClient1.ProtocolVersion := 'HTTP_2_0';
4

1 回答 1

2

这应该有效:

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:将代码更新为您在评论中的问题

于 2021-09-23T08:31:17.263 回答