TsgcHTTP2Client › 方法 › Connect
建立 HTTP/2 会话并执行阻塞式 GET 请求到指定 URL。
function Connect(const aURL: string): string;
| 名称 | 类型 | 描述 |
|---|---|---|
aURL | const string | 目标资源的绝对 URL。方案(https / http)决定使用 TLS 保护的 h2 还是明文 h2c。 |
从服务器接收的响应体,解码为字符串。(string)
此重载打开 TCP/TLS 传输,执行 ALPN/Upgrade 协商,发出初始 GET 请求,并在读取完整响应后返回。当您需要将完整载荷作为字符串保存在内存中时使用此方法。
vResponse := oClient.Connect('https://api.example.com/status');
procedure Connect(Const aURL: string; const aResponseContent: TStream);
| 名称 | 类型 | 描述 |
|---|---|---|
aURL | const string | 第一个 HTTP/2 请求所使用的目标资源的绝对 URL。 |
aResponseContent | const TStream | 调用方提供的流,接收响应正文;随着字节写入,位置会向前推进。适用于大负载或直接文件输出。 |
此流式重载与返回字符串的变体行为相同,但直接将响应写入提供的 TStream,避免中间字符串分配。当响应不需要保留在内存中时,建议使用此重载。
oStream := TFileStream.Create('out.bin', fmCreate);
try
oClient.Connect('https://api.example.com/download', oStream);
finally
oStream.Free;
end;