使用indy的IdHTTPServer控件
2009-01-12 22:30
176 查看
unit Unit1;
interface
uses
...... ActiveX,IdBaseComponent, IdComponent, IdCustomTCPServer, IdCustomHTTPServer,IdHTTPServer,IdTCPServer,IdContext;
type
......
procedure Server1CommandGet(AContext: TIdContext;ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
procedure WebBrowser1NavigateComplete2(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
protected
FHTMLDir: string;
FURL:string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
server1.Active:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FHTMLDir:= ExtractFilePath(Application.ExeName) + 'WEBROOT';
FURL:='http://127.0.0.1:'+inttostr(server1.DefaultPort)+'/';
end;
procedure TForm1.Server1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
LFilename: string;
LPathname: string;
begin
LFilename := ARequestInfo.Document;
if LFilename = '/' then begin
LFilename := '/index.html';
end;
LPathname := FHTMLDir + LFilename;
if FileExists(LPathname) then begin
AResponseInfo.ContentStream := TFileStream.Create(LPathname, fmOpenRead + fmShareDenyWrite);
end else begin
AResponseInfo.ResponseNo := 404;
AResponseInfo.ContentText := 'The requested URL ' + ARequestInfo.Document+ ' was not found on this server.';
end;
end;
initialization
OleInitialize(nil);
finalization
try
OleUninitialize;
except
end;
end.
interface
uses
...... ActiveX,IdBaseComponent, IdComponent, IdCustomTCPServer, IdCustomHTTPServer,IdHTTPServer,IdTCPServer,IdContext;
type
......
procedure Server1CommandGet(AContext: TIdContext;ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
procedure WebBrowser1NavigateComplete2(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
protected
FHTMLDir: string;
FURL:string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
server1.Active:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FHTMLDir:= ExtractFilePath(Application.ExeName) + 'WEBROOT';
FURL:='http://127.0.0.1:'+inttostr(server1.DefaultPort)+'/';
end;
procedure TForm1.Server1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
LFilename: string;
LPathname: string;
begin
LFilename := ARequestInfo.Document;
if LFilename = '/' then begin
LFilename := '/index.html';
end;
LPathname := FHTMLDir + LFilename;
if FileExists(LPathname) then begin
AResponseInfo.ContentStream := TFileStream.Create(LPathname, fmOpenRead + fmShareDenyWrite);
end else begin
AResponseInfo.ResponseNo := 404;
AResponseInfo.ContentText := 'The requested URL ' + ARequestInfo.Document+ ' was not found on this server.';
end;
end;
initialization
OleInitialize(nil);
finalization
try
OleUninitialize;
except
end;
end.
相关文章推荐
- c++ builder2010 indy控件idhttp, post页面获取数据(要注意编码的问题,双方都使用UTF-8最好)
- 跪求INDY10中idpop3和IdSSLIOHandlerSocketOpenSSL使用SSL连接Gmail用法,该怎么解决
- 学习indy组件之一idhttp的使用方法
- 各浏览器对使用 document.id 和 document.name 获取对象的支持存在差异
- 在Robotium中使用ID
- Python使用UUID库生成唯一ID
- 使用SPBuiltInFieldId更新task
- wps 使用中文ID
- 使用Shell脚本查找程序对应的进程ID,并杀死进程
- 牛腩购物4 aspnetpager控件的使用 以及 linkbutton 如何传值,判断传入的id值是否为数字
- 使用Gradle构建多个不同applicationId包
- 利用Indy 10的IdSMTP控件制作可带附件的邮件发送器
- [CSS]为什么不推荐在CSS中使用ID选择器
- [CSS]为什么不推荐在CSS中使用ID选择器
- 使用FMDB进行插入语句出现 obj = va_arg(args, id)错误
- HTML基础之为什么要在表单控件中同时使用name和id属性?
- Delphi组件indy 10中IdTCPServer修正及SSL使用心得
- Linq To EF 使用小知识(添加记录后获取添加的自增ID和叫“ID”的列不是自增列不让插入的问题)
- 安卓自动化测试工具MonkeyRunner之使用ID
- Jedis使用总结【pipeline】【分布式的id生成器】【分布式锁【watch】【multi】】【redis分布式】