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:=;
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:='
end;
end.
手机扫一扫
移动阅读更方便
你可能感兴趣的文章