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 ...
随机推荐
- python程序daemon化
1 直接空格加& python flask_server.py & 最简单的方式 这样还不行,不知道为什么flask server会自动退出. $ nohup python flask ...
- 以区间DP为前提的【洛谷p1063】能量项链
(跑去练习区间DP,然后从上午拖到下午qwq) 能量项链[题目链接] 然后这道题也是典型的区间DP.因为是项链,所以显然是一个环,然后我们可以仿照石子合并一样,把一个有n个节点的环延长成为有2*n个节 ...
- Python中map和reduce函数??
①从参数方面来讲: map()函数: map()包含两个参数,第一个是参数是一个函数,第二个是序列(列表或元组).其中,函数(即map的第一个参数位置的函数)可以接收一个或多个参数. reduce() ...
- go中string类型转换为基本数据类型的方法
代码 // string类型转基本数据类型 package main import ( "fmt" "strconv" ) func main() { str1 ...
- append动态生成的元素,无法触发事件的原因及解决方案
今天笔者在实现一个简单的动态生成元素功能的时候,发现了一个问题: 使用append动态生成的元素事件绑定失效了. 查阅资料后发现: click(fn)当选中的选择器被点击时触发回调函数fn.只针对与页 ...
- MTCNN 人脸检测
demo.py import cv2 from detection.mtcnn import MTCNN # 检测图片中的人脸 def test_image(imgpath): mtcnn = MTC ...
- java 回调的原理与实现
回调函数,顾名思义,用于回调的函数.回调函数只是一个功能片段,由用户按照回调函数调用约定来实现的一个函数.回调函数是一个工作流的一部分,由工作流来决定函数的调用(回调)时机. 回调原本应该是一个非常简 ...
- MYSQL学习笔记——数据类型
mysql的数据类型可以分为三大类,分别是数值数据类型.字符串数据类型以及日期时间数据类型. 数值数据类型 ...
- bui拍照上传、相册上传注意事项
1.控制台输入 bui.currentPlatform 可查看工程项目基于什么平台 如:bingotouch 2.如果是 bingotouch , 在 index.js 或者其它配置的地方, 加上 ...
- Prometheus + Node Exporter + Grafana 监控主机运行信息
上一篇文章中讲了如何利用Prometheus和Grafana监控SpringBoot应用的JVM信息,这次就来看看如何监控 服务器运行状态,先列出用到的工具: Prometheus node_ex ...