idHttpServer受信タイプ

6229 ワード

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:=' ';   }


//  AResponseInfo.ContentEncoding:='utf-8';
//  AResponseInfo.ContentType :='text/html';
//  AResponseInfo.ContentText:=' ';

  // html 
   {AResponseInfo.ContentEncoding:='utf-8';
   AResponseInfo.ContentType :='text/html';
   AResponseInfo.ContentText:=' '; }
   // xml 
   {AResponseInfo.ContentType :='text/xml';
   AResponseInfo.ContentText:=''
   +''
   +''+AnsiToUtf8(' ')+'14'
   +'bb16'
   +'';}


end;

end.