首页 > Web开发 > 详细

TWebHttpRequest使用

时间:2019-02-18 13:23:59      阅读:166      评论:0      收藏:0      [点我收藏+]

TWebHttpRequest使用

TWebHttpRequest通过HTTP GET方法,向中间件REST API申请数据。

procedure TForm1.WebButton1Click(Sender: TObject);
begin
  WebHttpRequest1.URL := ‘https://jsonplaceholder.typicode.com/albums‘;
  WebHttpRequest1.Execute;
end;

procedure TForm1.WebHttpRequest1Response(Sender: TObject; AResponse: string);
var
  js: TJSON;
  ja: TJSONArray;
  jo: TJSONObject;
  i: integer;
begin
  js := TJSON.Create;

  try
    ja := TJSONArray(js.Parse(AResponse));

    ShowMessage(‘Retrieved items:‘ +inttostr(ja.Count));

    for i := 0 to ja.Count - 1 do
    begin
      jo := TJSONObject(ja.Items[i]);
      WebListBox1.Items.Add(jo.GetJSONValue(‘title‘));
    end;
  finally
    js.Free;
  end;
end;

  

TWebHttpRequest使用

原文:https://www.cnblogs.com/hnxxcxg/p/10395022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!