delphi idhttpsever
http://blog.csdn.net/chelen_jak/article/details/50203809
delphi idhttpsever



- unit main;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, IdBaseComponent,IdContext ,IdComponent, IdCustomTCPServer, IdCustomHTTPServer,
- IdHTTPServer, StdCtrls;
- type
- TForm_main = class(TForm)
- IdHTTPServer1: TIdHTTPServer;
- Button_StartServer: TButton;
- Edit_Port: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Edit_Ip: TEdit;
- Button_stop: TButton;
- Label3: TLabel;
- Edit_RootDir: TEdit;
- Edit_index: TEdit;
- Label4: TLabel;
- procedure Button_StartServerClick(Sender: TObject);
- procedure Button_stopClick(Sender: TObject);
- procedure IdHTTPServer1CommandGet(AContext: TIdContext;
- ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form_main: TForm_main;
- implementation
- var
- RootDir:string;
- URL:string;
- {$R *.dfm}
- procedure TForm_main.Button_StartServerClick(Sender: TObject);
- begin
- try
- IdHTTPServer1.Bindings.Clear;
- //要绑定的端口,一定设置此项,这是真正要绑定的端口;
- IdHTTPServer1.DefaultPort:=strtoint(trim(edit_port.Text));
- IdHTTPServer1.Bindings.Add.IP := trim(edit_Ip.Text);
- //启动服务器
- IdHTTPServer1.Active := True;
- except
- showmessage('启动失败!');
- end;
- RootDir:=trim(edit_rootDir.Text);
- URL:='http://'+trim(edit_Ip.Text)+trim(edit_port.Text)+'/';
- end;
- procedure TForm_main.Button_stopClick(Sender: TObject);
- begin
- IdHTTPServer1.Active := false;
- end;
- procedure TForm_main.IdHTTPServer1CommandGet(AContext: TIdContext;
- ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
- var
- LFilename: string;
- LPathname: string;
- zhongwen:string;
- begin
- //浏览器请求http://127.0.0.1:8008/index.html?a=1&b=2
- //ARequestInfo.Document 返回 /index.html
- //ARequestInfo.QueryParams 返回 a=1b=2
- //ARequestInfo.Params.Values['name'] 接收get,post过来的数据
- ////webserver发文件
- {LFilename := ARequestInfo.Document;
- if LFilename = '/' then
- begin
- LFilename := '/'+trim(edit_index.Text);
- end;
- LPathname := RootDir + LFilename;
- if FileExists(LPathname) then
- begin
- AResponseInfo.ContentStream := TFileStream.Create(LPathname, fmOpenRead + fmShareDenyWrite);//发文件
- end
- else begin
- AResponseInfo.ResponseNo := 404;
- AResponseInfo.ContentText := '找不到' + ARequestInfo.Document;
- end;}
- //发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>';}
- //下载文件时,直接从网页打开而没有弹出保存对话框的问题解决
- //AResponseInfo.CustomHeaders.Values['Content-Disposition'] :='attachment; filename="'+文件名+'"';
- //替换 IIS
- {AResponseInfo.Server:='IIS/6.0';
- AResponseInfo.CacheControl:='no-cache';
- AResponseInfo.Pragma:='no-cache';
- AResponseInfo.Date:=Now;}
- end;
- end.
delphi idhttpsever的更多相关文章
- Delphi IdHttp组件+IdHttpServer组件实现文件下载服务
http://blog.csdn.net/xxkku521/article/details/16864759 Delphi IdHttp组件+IdHttpServer组件实现文件下载服务 2013- ...
- 学习笔记:7z在delphi的应用
最近做个发邮件的功能,需要将日志文件通过邮件发送回来用于分析,但是日志文件可能会超级大,测算下来一天可能会有800M的大小.所以压缩是不可避免了,delphi中的默认压缩算法整了半天不太好使,就看了看 ...
- delphi连接sql存储过程
针对返回结果为参数的 一. 先建立自己的存储过程 ALTER PROCEDURE [dbo].[REName] ) AS BEGIN select ROW_NUMBER() over(order by ...
- delphi 2010与delphi XE破解版的冲突
在系统中同时安装了Dephi 2010LITE版与Delphi XE lite后,总是会有一个有问题 是因为两者都是读取C:\ProgramData\Embarcadero目录下的license文件, ...
- [Delphi] Delphi版本号对照
VER300 Delphi Seattle / C++Builder Seattle 23 230 (Delphi:Win32/Win64/OSX/iOS32/iOS64/An ...
- delphi tidhttp 超时设置无效的解决方法
现在delphi都发布到xe8了,tidhttp还有缺陷,那就是超时设置在没有网络或者连不上服务器的时候是无效的,不管你设置为多少都要10-20秒.connectTimeout和readTimeout ...
- Delphi Code Editor 之 编辑器选项
Delphi Code Editor 之 编辑器选项 可从Code Editor的右键菜单中选择“Properties”菜单项来查看编辑器选项.也可以从主菜单[Tools | Editor Optio ...
- Delphi使用ADO进行数据库编程
Delphi是一个可视化的编程工具,ADO编程也是这样,所以话不多言,直接通过代码.截图和语言来说明. 我的数据库是Oracle,为了测试,先建一个表:create table practice(un ...
- 怎么使用Delphi获取当前的时间,精确到毫秒
先介绍一个可能比较常用的方法,获取当前时间 var datetime: string; begin datetime:= FormatDateTime('yyyy-mm-dd hh:mm:ss', N ...
随机推荐
- CentOS7 修复grub.cfg文件
为了达到实验目的,首先删除grub.cfg文件 重启后发现系统进不去了,这正是我们想要的 进入系统救援模式,通过输入以下命令修复grub.cfg文件 重启后发现能正常引导进入系统了
- JDK8 parallelStream性能测试
https://blog.csdn.net/u011870280/article/details/80700993 public static void main(String[] args) {lo ...
- UVA-10462.Is There A Second Way Left(Kruskal+次小生成树)
题目链接 本题大意:这道题用Kruskal较为容易 参考代码: #include <cstdio> #include <cstring> #include <vector ...
- mysql-介绍、下载安装以及软件基本管理
一.mysql介绍 mysql是一个关系型数据库管理系统,它是一个基于socket编写的C/S架构的软件. 客户端软件: mysql自带:如mysql命令,mysqldump命令等. python模块 ...
- P3064 [USACO12DEC]伊斯坦布尔的帮派 (模拟)
题目传送门 题意: 一片草地,每次可以只可以让一种牛占领,问你怎样安排牛的次序 最后剩下的是1号牛,并且输出其数量 思路: 看到n到100 ,所以可以(n^3)暴力,第一重遍历次序,第二枚举是哪只牛 ...
- 纯css实现网上商城左侧垂直商品分类菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- nodejs npm资料
安装淘宝的 cnpm : npm install --global cnpm 不想安装 cnpm 又想使用淘宝的服务器来下载 : npm install jquery --registry=http ...
- 初学Java 数组统计字母
public class CountLetterInArray { public static void main(String[] args) { char[] chars = createArra ...
- eclipse的代码格式化的个性配置
1.安装jdk a. 到http://www.oracle.com/technetwork/java/javase/downloads/index.html 下载对应版本的jdk,安装到自己电脑上. ...
- [python 学习] 编码
一.源文件编码(encoding: utf-8) 1. python 2.x 默认按ascii编码读取源文件,源码中出现了ascii不能表示的字符 "的",所以报错(3.x版本不报 ...