TsgcHTTP2Client › 方法 › Get
执行同步 HTTP/2 GET 并阻塞,直到收到完整响应。
function Get(const aURL: string): string;
| 名称 | 类型 | 描述 |
|---|---|---|
aURL | const string | 要获取的资源的绝对 URL。查询字符串参数应已编码。 |
从服务器接收的响应体,解码为字符串。(string)
当响应为文本(HTML、JSON、XML)且能舒适地保存在内存中时,使用此重载。该方法阻塞直到所有 DATA 帧收到,并返回拼接后的正文。
vJSON := oClient.Get('https://api.example.com/v1/users');
procedure Get(Const aURL: string; const aResponseContent: TStream);
| 名称 | 类型 | 描述 |
|---|---|---|
aURL | const string | 要获取的资源的绝对 URL。 |
aResponseContent | const TStream | 调用方拥有的流,用于接收原始响应字节(随到随写)。 |
面向流的变体,适用于二进制下载或不适合将响应体保存为字符串的大载荷。响应将顺序写入 aResponseContent(例如 TFileStream)。
oStream := TFileStream.Create('image.png', fmCreate);
try
oClient.Get('https://api.example.com/image.png', oStream);
finally
oStream.Free;
end;