TsgcHTTP3Client › 方法 › Put

Put 方法

发送携带正文负载的同步 HTTP/3 PUT 请求并返回响应体。

语法

function Put(const aURL: string; const aData: string; const aContentType: string = 'application/json'): string; overload;
procedure Put(const aURL: string; const aSource: TStream; const aResponseContent: TStream); overload;

参数

名称类型描述
aURLconst string请求发送目标资源的绝对 URL。
aDataconst string发送给服务器的请求正文。
aContentTypeconst stringcontent-type 标头的值。默认为 application/json。
aSourceTStream用作请求正文的流(仅流重载)。
aResponseContentTStream接收原始响应体的流(仅流重载)。

返回值

从服务器接收的响应体,解码为字符串。流重载将正文写入 aResponseContent。(string)

备注

Put 阻塞调用线程直至收到完整的 HTTP/3 响应。使用第一个重载发送字符串正文,并将 aContentType 设为与负载匹配的值;使用流重载从 TStream 发送请求正文并将回复写入另一个流。如需非阻塞请求,请使用 PutAsync,它将回复传递到 OnResponse。

示例


vResponse := oClient.Put('https://api.example.com/v1/users/42', '{"name":"john"}');

返回方法