TsgcHTTP2Client › Methods › Put
执行同步 HTTP/2 PUT 请求,将 URL 处的资源替换为上传的内容。
function Put(const aURL: string; const aSource: TStream): string;
| 名称 | 类型 | 描述 |
|---|---|---|
aURL | const string | 标识将要创建或替换的资源的绝对 URL。 |
aSource | const TStream | 提供要存储的资源完整表示的流。 |
从服务器接收的响应体,解码为字符串。(string)
PUT 是幂等的:使用相同请求体重复调用会在服务器上产生相同的资源状态。此重载适用于文本响应可作为字符串消费的 JSON/文本载荷。
oBody := TStringStream.Create('{"status":"active"}');
try
oClient.Request.ContentType := 'application/json';
vResponse := oClient.Put('https://api.example.com/users/42', oBody);
finally
oBody.Free;
end;
procedure Put(const aURL: string; const aSource: TStream; const aResponseContent: TStream);
| 名称 | 类型 | 描述 |
|---|---|---|
aURL | const string | 标识要创建或替换的资源的绝对 URL。 |
aSource | const TStream | 提供要上传的资源字节的流。 |
aResponseContent | const TStream | 捕获服务器原始响应体的流。 |
推荐用于二进制资源上传的流对流变体,例如图像或文件替换,此时请求和响应均最好不经过字符串转换处理。
oIn := TFileStream.Create('avatar.png', fmOpenRead);
oOut := TMemoryStream.Create;
try
oClient.Put('https://api.example.com/users/42/avatar', oIn, oOut);
finally
oOut.Free;
oIn.Free;
end;