delphi idhttpsever+idhttp 实现简单的JSON API服务

http服务器测试代码

procedure TForm1.FormShow(Sender: TObject);
begin
IdHTTPServer1.Bindings.Clear;
IdHTTPServer1.DefaultPort:= 6600;
IdHTTPServer1.Bindings.Add.IP := '127.0.0.1';
//启动服务器
IdHTTPServer1.Active := True;

end;

procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  I: Integer;
begin
  if SameText(ARequestInfo.Command, 'get') then
  begin
    if ARequestInfo.Document = '/api_v1/get_token' then
    begin
      Memo1.Lines.Add('-------------');
      Memo1.Lines.Add(ARequestInfo.Params.Count.ToString);
      Memo1.Lines.Add('-------------');
      for I := 0 to ARequestInfo.Params.Count - 1 do
      begin
        Memo1.Lines.Add(ARequestInfo.Params.ValueFromIndex[I]);
      end;
      Memo1.Lines.Add('-------------');
      AResponseInfo.CharSet := 'UTF-8';
      AResponseInfo.ContentType := 'application/json';
      AResponseInfo.ContentText := '{a:"001

你可能感兴趣的:(windows编程(PC))