TsgcHTTP2ClientMethods › Put

Put 方法

执行同步 HTTP/2 PUT 请求,将 URL 处的资源替换为上传的内容。

重载

重载 1

语法

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

参数

名称类型描述
aURLconst string标识将要创建或替换的资源的绝对 URL。
aSourceconst 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;

重载 2

语法

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

参数

名称类型描述
aURLconst string标识要创建或替换的资源的绝对 URL。
aSourceconst TStream提供要上传的资源字节的流。
aResponseContentconst 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;

返回方法