idHttpServer接收类型

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPServer,
  IdCustomHTTPServer, IdHTTPServer;

type
  TForm1 = class(TForm)
    btn1: TButton;
    IdHTTPServer1: TIdHTTPServer;
    mmo1: TMemo;
    procedure btn1Click(Sender: TObject);
    procedure IdHTTPServer1CommandGet(AThread: TIdPeerThread;
      ARequestInfo: TIdHTTPRequestInfo;
      AResponseInfo: TIdHTTPResponseInfo);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
begin
 try
    IdHTTPServer1.Bindings.Clear;
    //要绑定的端口,一定设置此项,这是真正要绑定的端口;
    IdHTTPServer1.DefaultPort:=8080;
    IdHTTPServer1.Bindings.Add.IP := '192.168.1.100';
    //启动服务器
    IdHTTPServer1.Active := True;
    mmo1.Lines.Add('启动');
  except
     showmessage('启动失败!');
  end;

end;

procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin

  mmo1.Lines.Add(ARequestInfo.Document);
//  mmo1.Lines.Add(ARequestInfo.QueryParams);
//  mmo1.Lines.Add(ARequestInfo.Params.Values['Par1'] );
//  mmo1.Lines.Add(ARequestInfo.Params.Values['Par2'] );
//  mmo1.Lines.Add(ARequestInfo.Command);

  //mmo1.Lines.Add(ARequestInfo.u);

  AResponseInfo.ContentType :='text/json';
  AResponseInfo.ContentText:='a:1,b:2';

{  AResponseInfo.ContentEncoding:='utf-8';
    AResponseInfo.ContentType :='text/html';
  AResponseInfo.ContentText:='<html><body>好</body></html>';   }


//  AResponseInfo.ContentEncoding:='utf-8';
//  AResponseInfo.ContentType :='text/html';
//  AResponseInfo.ContentText:='<html><body>好</body></html>';

  //发html文件
   {AResponseInfo.ContentEncoding:='utf-8';
   AResponseInfo.ContentType :='text/html';
   AResponseInfo.ContentText:='<html><body>好</body></html>'; }
   //发xml文件
   {AResponseInfo.ContentType :='text/xml';
   AResponseInfo.ContentText:='<?xml version="1.0" encoding="utf-8"?>'
   +'<students>'
   +'<student sex = "male"><name>'+AnsiToUtf8('陈')+'</name><age>14</age></student>'
   +'<student sex = "female"><name>bb</name><age>16</age></student>'
   +'</students>';}


end;

end.
书搞进脑袋 创新 创造; 积极
原文地址:https://www.cnblogs.com/tobetterlife/p/12169526.html