德尔福REST API样品后 [英] Delphi REST API Post Sample

查看:114
本文介绍了德尔福REST API样品后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否有人张贴JSON POST请求使用Delphi 2005的API的一个简单的例子,我发现使用GET的例子不胜枚举,但API提供商不允许通过HTTP GET请求,不支持URL编码参数。

Can someone post a simple example of a JSON POST request to an API using Delphi 2005. I have found numerous examples using GET but the API provider does not allow requests via HTTP GET and does not support URL encoding parameters.

我是全新的调用REST服务(已经在过去使用SOAP),所以请让我知道如果你需要更多的信息。

I am brand new to calling REST services (have used SOAP in the past) so please let me know if you require more information.

推荐答案

您只想用Indy的 TIdHTTP 组件,并调用发表方法。通过URL作为第一个参数,你的JSON字符串作为第二个参数。事情是这样的:

You would just use Indy's TIdHTTP component and call the Post method. Pass the URL as the first argument and your JSON string as the second argument. Something like this:

procedure TForm1.Button1Click(Sender: TObject);

  var    jsonToSend:TStringList;
         http:TIDHttp;
  begin
  http := TIDHttp.Create(nil);
  http.HandleRedirects := true;
  http.ReadTimeout := 5000;
  jsonToSend:=TStringList.create;
  jsonToSend.Add('{ Your JSON-encoded request goes here }');
  Memo1.Lines.Text:=http.Post('http://your.restapi.url', jsonToSend);
  jsonToSend.Destroy;
  http.Destroy;
  end;
end.

我假设你已经能够连接code和德code中的JSON和你刚才问如何用Delphi执行一个HTTP POST。

I'm assuming you are already able to encode and decode the JSON and that you were just asking how to perform an HTTP post using Delphi.

这篇关于德尔福REST API样品后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆