我需要在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/