TsgcHTTP2Client › 方法 › GetFuture
在后台线程中执行 HTTP/2 GET,并返回一个解析为响应正文的 future。
function GetFuture(const aURL: string): IsgcFuture<string>;
| 名称 | 类型 | 描述 |
|---|---|---|
aURL | const string | 要检索的资源的绝对 URL。 |
一个 IsgcFuture<string>,解析为响应正文。调用 Await 阻塞直到响应到达,调用 ThenProc 在延续中使用正文,调用 OnError 处理故障,调用 Cancel 中止请求。
GetFuture 是同步方法 Get 的 future 风格对应方法:请求在后台线程中执行,方法立即返回,因此调用线程永远不会被阻塞。与 ConnectAsync 及其他 Async 方法不同,它不需要事件处理程序:响应通过返回的 future 传递。调用 Cancel 会断开客户端连接,因此仍在等待响应的请求会被中止而不是执行到结束;被中止或失败的请求会以异常拒绝该 future,该异常会传递给 OnError(或由 Await 重新引发)。需要 Delphi 2010 或更高版本(以及 C++Builder 2010 或更高版本);在 .NET 版本中不可用。
oClient.GetFuture('https://www.esegece.com')
.ThenProc(procedure(const aBody: string)
begin
WriteLn(aBody);
end)
.OnError(procedure(E: Exception)
begin
WriteLn('Request failed: ' + E.Message);
end);