TsgcHTTP2Client › 方法 › Patch
执行同步 HTTP/2 PATCH,对目标资源进行部分修改。
function Patch(const aURL: string; const aSource: TStream): string;
| 名称 | 类型 | 描述 |
|---|---|---|
aURL | const string | 要部分更新的资源的绝对 URL。 |
aSource | const TStream | 保存补丁文档的流(例如 JSON Patch 或 JSON Merge Patch 主体)。 |
服务器返回的响应体,已解码为字符串。(string)
与 PUT 不同,PATCH 只发送应更改的字段。确保 Request.ContentType 与服务器期望的补丁格式匹配(例如 application/json-patch+json 或 application/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;
procedure Patch(const aURL: string; const aSource: TStream; const aResponseContent: TStream);
| 名称 | 类型 | 描述 |
|---|---|---|
aURL | const string | 要部分更新的资源的绝对 URL。 |
aSource | const TStream | 包含补丁负载的流。 |
aResponseContent | const 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;