TsgcHTTP2Client方法 › Patch

Patch 方法

执行同步 HTTP/2 PATCH,对目标资源进行部分修改。

重载

重载 1

语法

function Patch(const aURL: string; const aSource: TStream): string;

参数

名称类型描述
aURLconst string要部分更新的资源的绝对 URL。
aSourceconst TStream保存补丁文档的流(例如 JSON Patch 或 JSON Merge Patch 主体)。

返回值

服务器返回的响应体,已解码为字符串。(string

备注

与 PUT 不同,PATCH 只发送应更改的字段。确保 Request.ContentType 与服务器期望的补丁格式匹配(例如 application/json-patch+jsonapplication/merge-patch+json)。

示例

oBody := TStringStream.Create('{"email":"new@example.com"}');
try
  oClient.Request.ContentType := 'application/merge-patch+json';
  vResponse := oClient.Patch('https://api.example.com/users/42', oBody);
finally
  oBody.Free;
end;

重载 2

语法

procedure Patch(const aURL: string; const aSource: TStream; const aResponseContent: TStream);

参数

名称类型描述
aURLconst string要部分更新的资源的绝对 URL。
aSourceconst TStream包含补丁负载的流。
aResponseContentconst TStream捕获来自服务器的原始响应的流。

备注

完全流式传输变体。适用于补丁文档或响应表示形式足够大以至于字符串往返会造成浪费的情况。

示例

oIn := TFileStream.Create('patch.json', fmOpenRead);
oOut := TMemoryStream.Create;
try
  oClient.Patch('https://api.example.com/users/42', oIn, oOut);
finally
  oOut.Free;
  oIn.Free;
end;

返回方法