delphi idhttpsever
http://blog.csdn.net/chelen_jak/article/details/50203809
delphi idhttpsever
Delphi(54) 
- 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 ...
随机推荐
- [Python3] 005 列表的基本使用
目录 1. 列表概述 2. 创建列表 3. 列表常用操作 (1) 访问列表 (2) 分片操作 1) 正向操作 2) 反向操作 3) 内置函数 id() 加入队伍 1. 列表概述 一组有顺序的数据的组合 ...
- mybatis工作流程&源码详解
该篇主要讲解的是mybatis从seesion创建到执行sql语句的流程 流程主线: 1.创建SqlSessionFactoryBuilder 2.创建会话工厂SqlSessionFactory 3. ...
- 关于toString()和valueOf()以及Object.prototype.toString.call()的结合理解
一.先说说String(): String()是全局函数,把对象的值转换为字符串. 语法:String(obj); 任何值(对象)都有String()方法,执行过程是这样的:首先,如果该对象上有toS ...
- 打开虚拟机提示 无法获得vmci 驱动程序的版本:句柄无效
我从另一台电脑复制过来虚拟机,提示如题. 找到 我的虚拟机的 *.vmx文件(如NeoKylin.vmx),其中有 vmci0.present = "TRUE",将TRUE改为 ...
- Vue+axios+Node+express实现文件上传(用户头像上传)
Vue 页面的代码 <label for='my_file' class="theme-color"> <mu-icon left value="bac ...
- HDU 4013 Distinct Subtrees(树的最小表示)
Distinct Subtrees Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Other ...
- CentOS7 安装Postgresql 11+ 源码编译安装Postgis-2.5.2
####安装Postgresql-11yum install zlib-devel gcc makegroupadd postgresuseradd -g postgres postgrespassw ...
- .net 关于路径的总结
原文:https://www.cnblogs.com/hehehehehe/p/6196155.html https://www.cnblogs.com/yugongmengjiutian/artic ...
- Webpack和Gulp对比
Webpack和Gulp对比 作者 彬_仔 关注 2016.10.19 22:42* 字数 8012 阅读 2471评论 18喜欢 68 在现在的前端开发中,前后端分离.模块化开发.版本控制.文件合并 ...
- C++多态下的访问修饰符
C++多态下的访问修饰符 先上代码: class Parent { public: virtual void showMsg() { cout << "Parent showMs ...