delphi - 将 cURL 格式转换为 Delphi

标签 delphi curl

我需要在Delphi中模仿这个Curl命令,我该怎么做?

curl -X POST \
https://api.encurtador.dev/encurtamentos \
-H 'content-type: application/json' \
-d '{ "url": "https://google.com" }'

最佳答案

uses
  REST.Client, REST.Types;

function cUrlCall: string;
begin
  var client := TRESTClient.Create('https://api.encurtador.dev');
  try
    var request := TRESTRequest.Create(client);
    request.Method := rmPOST;
    request.Resource := 'encurtamentos';
    request.AddBody('{ "url": "https://google.com" }', TRESTContentType.ctAPPLICATION_JSON);
    request.Execute;
    Result := request.Response.Content;
  finally
    client.Free;
  end;
end;

关于delphi - 将 cURL 格式转换为 Delphi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73390319/

相关文章:

delphi - 如何添加设置并进行设置,然后将其内置到Delphi中的现有exe文件中

Delphi:如何重写 ShortDateFormat?

linux - 执行从文件中读取的 curl 命令

django - 使用Django Rest框架在发布请求时获取自定义 header

PHP 验证 Playstation 网络

php - 如何在 PHP cURL 中提供 Youtube 身份验证 token

delphi - Delphi 2009 项目配置选项集的层次结构如何?

multithreading - 为什么在通过 OnClose 事件(在线程中)释放表单后不显示 MessageDlg

c++ - 如何注册 Windows 服务但避免它被列在服务控制台中?

asp.net - 使用 Web 服务导致 “Unable to handle request without a valid action parameter”