如何启用 HTTP2 Delphi 11?我一直在尝试使用代码,但无法正常工作
NetHTTPClient1.ProtocolVersion := 'HTTP_2_0';
如何启用 HTTP2 Delphi 11?我一直在尝试使用代码,但无法正常工作
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:将代码更新为您在评论中的问题