打造自己的Web(HTTP)服务器
来源:互联网 发布:口袋妖怪xy存档数据坏 编辑:程序博客网 时间:2024/04/29 23:19
使用indy的IdHTTPServer控件:(限于篇幅,部分内容省略)
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.
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.
- 打造自己的Web(HTTP)服务器
- 打造自己的HTTP代理服务器
- 打造自己的HTTP代理服务器
- 利用socket自己实现基于HTTP协议的Web服务器
- 自己来做一个简单的web服务器(一)理解基本的http协议
- 打造自己的个性化邮件服务器
- 用Mac打造自己的DNS服务器
- 基于Nettty打造自己的MVC服务器
- 打造自己的安全Windows Web服务
- 如何打造一个安全的WEB服务器
- 打造安全的2003个人Web服务器
- 打造最安全的Nginx Web服务器
- 【一步一个脚印】Tomcat+MySQL为自己的APP打造服务器(1)服务器环境搭建
- 【一步一个脚印】Tomcat+MySQL为自己的APP打造服务器(1)服务器环境搭建
- 【一步一个脚印】Tomcat+MySQL为自己的APP打造服务器(1)服务器环境搭建
- HTTP Web服务器研究之三 打造一款轻量级web服务器
- 自己写的web服务器
- 【一步一个脚印】Tomcat+MySQL为自己的APP打造服务器(2-1)Servlet的使用
- 动态加载类的原理——元数据的使用
- makefile入门
- 在线版的《Windows程序设计》
- 今天终于搞定ORACLE了
- IIS 6 出于安全考虑, 默认最大请求200K do what?
- 打造自己的Web(HTTP)服务器
- (Sql Server高级技巧)使用SQL语句实现备份与还原
- 什么是托管
- Delphi防止同时出现多个应用程序实例之改进
- 涂涂评:读《不要祈求太多》有感
- DateChooser控件发布ASP.NET 2.0新版(我的ASP.NET 2.0控件开发书的第二个阶段项目)
- 处理sqlcommand里面的参数
- 创建、查询、修改带名称空间的 XML 文件的例子
- Linux程序设计——用getopt处理命令行参数