I need to send PUT and DELETE along with POST, GET to a REST API how can I do it?
我需要发送PUT和DELETE以及POST,GET到REST API我该怎么办?
3 个解决方案
#1
9
Delphi 7 comes with Indy. See the TIdHTTP component and specificly the Get and Put methods.
Delphi 7附带Indy。请参阅TIdHTTP组件,特别是Get和Put方法。
#2
4
Or look at the open source Synapse library. There are some simple function calls in the HTTPSend unit which make implementing this completely painless. Just use the sample functions/procedures as your model for the PUT/DELETE. The existing routines already supply the POST and GET. The difference is in the method passed.
或者看看开源的Synapse库。在HTTPSend单元中有一些简单的函数调用,这使得实现它完全无痛。只需使用示例函数/过程作为PUT / DELETE的模型。现有的例程已经提供了POST和GET。不同之处在于传递的方法。
Personally I have found this library to be perfectly matched for working with REST. Its simple, well written and easy to extend.
就个人而言,我发现这个库与REST一起完全匹配。它简单,编写良好,易于扩展。
For example, here is a simple put that sends and receives a stream:
例如,这是一个发送和接收流的简单put:
function HttpPutBinary(const URL: string; const Data: TStream): Boolean;
var
HTTP: THTTPSend;
begin
HTTP := THTTPSend.Create;
try
HTTP.Document.CopyFrom(Data, 0);
HTTP.MimeType := 'Application/octet-stream';
Result := HTTP.HTTPMethod('PUT', URL); // changed method from 'POST'
Data.Size := 0;
if Result then
begin
Data.Seek(0, soFromBeginning);
Data.CopyFrom(HTTP.Document, 0);
end;
finally
HTTP.Free;
end;
end;
#1
9
Delphi 7 comes with Indy. See the TIdHTTP component and specificly the Get and Put methods.
Delphi 7附带Indy。请参阅TIdHTTP组件,特别是Get和Put方法。
#2
4
Or look at the open source Synapse library. There are some simple function calls in the HTTPSend unit which make implementing this completely painless. Just use the sample functions/procedures as your model for the PUT/DELETE. The existing routines already supply the POST and GET. The difference is in the method passed.
或者看看开源的Synapse库。在HTTPSend单元中有一些简单的函数调用,这使得实现它完全无痛。只需使用示例函数/过程作为PUT / DELETE的模型。现有的例程已经提供了POST和GET。不同之处在于传递的方法。
Personally I have found this library to be perfectly matched for working with REST. Its simple, well written and easy to extend.
就个人而言,我发现这个库与REST一起完全匹配。它简单,编写良好,易于扩展。
For example, here is a simple put that sends and receives a stream:
例如,这是一个发送和接收流的简单put:
function HttpPutBinary(const URL: string; const Data: TStream): Boolean;
var
HTTP: THTTPSend;
begin
HTTP := THTTPSend.Create;
try
HTTP.Document.CopyFrom(Data, 0);
HTTP.MimeType := 'Application/octet-stream';
Result := HTTP.HTTPMethod('PUT', URL); // changed method from 'POST'
Data.Size := 0;
if Result then
begin
Data.Seek(0, soFromBeginning);
Data.CopyFrom(HTTP.Document, 0);
end;
finally
HTTP.Free;
end;
end;