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 ...
随机推荐
- js转换后台接受的日期格式
var html = "--";if(data.createTime!=null&&data.createTime!=""){ Date.pro ...
- 日记smarthome
测试命令:测试命令 7e 7e 两个字节 一个字节 两个字节 一个字节 解释: 两个字节是userid的值 int Userid = data[i] * 256 + data[i + 1]; ...
- [AHOI2013]作业 (莫队+分块)
[AHOI2013]作业 (莫队+分块) 题面 给定了一个长度为n的数列和若干个询问,每个询问是关于数列的区间[l,r],首先你要统计该区间内大于等于a,小于等于b的数的个数,其次是所有大于等于a,小 ...
- poj1305 Fermat vs. Pythagoras(勾股数)
题目传送门 题意: 设不定方程:x^2+y^2=z^2若正整数三元组(x,y,z)满足上述方程,则称为毕达哥拉斯三元组.若gcd(x,y,z)=1,则称为本原的毕达哥拉斯三元组. 定理:正整数x,y, ...
- 固定标签(position: fixed)
document.body.scrollTop 要改成 document.documentElement.scrollTop不然不生效 <!DOCTYPE html> <html l ...
- 第一个progressive web application,发车!
progressive web application是谷歌推出的一种渐进式web应用,通过利用service-worker等来达到类似于原生应用,而且在chrome浏览器还可以添加到主页,完全就和一 ...
- linux下查看Apache的访问日志及ip
linux下查看Apache的实时访问日志:tail -f /etc/httpd/logs/access_log 查看有哪些ip访问过:cat access_log |awk '{print $1} ...
- mysql 乐观锁、悲观锁、共享锁,排它锁
mysql锁机制分为表级锁和行级锁,本文就和大家分享一下我对mysql中行级锁中的共享锁与排他锁进行分享交流. 共享锁又称为读锁,简称S锁,顾名思义,共享锁就是多个事务对于同一数据可以共享一把锁,都能 ...
- CSS多列布局(栅格布局)
一.多列布局 CSS3 可以将文本内容设计成像报纸一样的多列布局,如下实例: 代码如下(具体的解释也在代码中)浏览器支持表格中的数字表示支持该方法的第一个浏览器的版本号. 紧跟在数字后面的 -webk ...
- Zabbix分布式监控系统实践
https://www.zabbix.com/wiki/howto/install/Ubuntu/ubuntuinstall 环境介绍OS: Ubuntu 10.10 Server 64-bitSer ...