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

delphi idhttpsever

2015-12-07 11:36 216人阅读 评论(0) 收藏 举报
 分类:
Web(57)  Delphi(54) 
转自:http://3699119.blog.163.com/blog/static/167075351201373024054586/

  1. unit main;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, IdBaseComponent,IdContext ,IdComponent, IdCustomTCPServer, IdCustomHTTPServer,
  6. IdHTTPServer, StdCtrls;
  7. type
  8. TForm_main = class(TForm)
  9. IdHTTPServer1: TIdHTTPServer;
  10. Button_StartServer: TButton;
  11. Edit_Port: TEdit;
  12. Label1: TLabel;
  13. Label2: TLabel;
  14. Edit_Ip: TEdit;
  15. Button_stop: TButton;
  16. Label3: TLabel;
  17. Edit_RootDir: TEdit;
  18. Edit_index: TEdit;
  19. Label4: TLabel;
  20. procedure Button_StartServerClick(Sender: TObject);
  21. procedure Button_stopClick(Sender: TObject);
  22. procedure IdHTTPServer1CommandGet(AContext: TIdContext;
  23. ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
  24. private
  25. { Private declarations }
  26. public
  27. { Public declarations }
  28. end;
  29. var
  30. Form_main: TForm_main;
  31. implementation
  32. var
  33. RootDir:string;
  34. URL:string;
  35. {$R *.dfm}
  36. procedure TForm_main.Button_StartServerClick(Sender: TObject);
  37. begin
  38. try
  39. IdHTTPServer1.Bindings.Clear;
  40. //要绑定的端口,一定设置此项,这是真正要绑定的端口;
  41. IdHTTPServer1.DefaultPort:=strtoint(trim(edit_port.Text));
  42. IdHTTPServer1.Bindings.Add.IP := trim(edit_Ip.Text);
  43. //启动服务器
  44. IdHTTPServer1.Active := True;
  45. except
  46. showmessage('启动失败!');
  47. end;
  48. RootDir:=trim(edit_rootDir.Text);
  49. URL:='http://'+trim(edit_Ip.Text)+trim(edit_port.Text)+'/';
  50. end;
  51. procedure TForm_main.Button_stopClick(Sender: TObject);
  52. begin
  53. IdHTTPServer1.Active := false;
  54. end;
  55. procedure TForm_main.IdHTTPServer1CommandGet(AContext: TIdContext;
  56. ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
  57. var
  58. LFilename: string;
  59. LPathname: string;
  60. zhongwen:string;
  61. begin
  62. //浏览器请求http://127.0.0.1:8008/index.html?a=1&b=2
  63. //ARequestInfo.Document  返回    /index.html
  64. //ARequestInfo.QueryParams 返回  a=1b=2
  65. //ARequestInfo.Params.Values['name']   接收get,post过来的数据
  66. ////webserver发文件
  67. {LFilename := ARequestInfo.Document;
  68. if LFilename = '/' then
  69. begin
  70. LFilename := '/'+trim(edit_index.Text);
  71. end;
  72. LPathname := RootDir + LFilename;
  73. if FileExists(LPathname) then
  74. begin
  75. AResponseInfo.ContentStream := TFileStream.Create(LPathname, fmOpenRead + fmShareDenyWrite);//发文件
  76. end
  77. else begin
  78. AResponseInfo.ResponseNo := 404;
  79. AResponseInfo.ContentText := '找不到' + ARequestInfo.Document;
  80. end;}
  81. //发html文件
  82. {AResponseInfo.ContentEncoding:='utf-8';
  83. AResponseInfo.ContentType :='text/html';
  84. AResponseInfo.ContentText:='<html><body>好</body></html>'; }
  85. //发xml文件
  86. {AResponseInfo.ContentType :='text/xml';
  87. AResponseInfo.ContentText:='<?xml version="1.0" encoding="utf-8"?>'
  88. +'<students>'
  89. +'<student sex = "male"><name>'+AnsiToUtf8('陈')+'</name><age>14</age></student>'
  90. +'<student sex = "female"><name>bb</name><age>16</age></student>'
  91. +'</students>';}
  92. //下载文件时,直接从网页打开而没有弹出保存对话框的问题解决
  93. //AResponseInfo.CustomHeaders.Values['Content-Disposition'] :='attachment; filename="'+文件名+'"';
  94. //替换 IIS
  95. {AResponseInfo.Server:='IIS/6.0';
  96. AResponseInfo.CacheControl:='no-cache';
  97. AResponseInfo.Pragma:='no-cache';
  98. AResponseInfo.Date:=Now;}
  99. end;
  100. end.

delphi idhttpsever的更多相关文章

  1. Delphi IdHttp组件+IdHttpServer组件实现文件下载服务

     http://blog.csdn.net/xxkku521/article/details/16864759 Delphi IdHttp组件+IdHttpServer组件实现文件下载服务 2013- ...

  2. 学习笔记:7z在delphi的应用

    最近做个发邮件的功能,需要将日志文件通过邮件发送回来用于分析,但是日志文件可能会超级大,测算下来一天可能会有800M的大小.所以压缩是不可避免了,delphi中的默认压缩算法整了半天不太好使,就看了看 ...

  3. delphi连接sql存储过程

    针对返回结果为参数的 一. 先建立自己的存储过程 ALTER PROCEDURE [dbo].[REName] ) AS BEGIN select ROW_NUMBER() over(order by ...

  4. delphi 2010与delphi XE破解版的冲突

    在系统中同时安装了Dephi 2010LITE版与Delphi XE lite后,总是会有一个有问题 是因为两者都是读取C:\ProgramData\Embarcadero目录下的license文件, ...

  5. [Delphi] Delphi版本号对照

    VER300    Delphi Seattle / C++Builder Seattle    23    230    (Delphi:Win32/Win64/OSX/iOS32/iOS64/An ...

  6. delphi tidhttp 超时设置无效的解决方法

    现在delphi都发布到xe8了,tidhttp还有缺陷,那就是超时设置在没有网络或者连不上服务器的时候是无效的,不管你设置为多少都要10-20秒.connectTimeout和readTimeout ...

  7. Delphi Code Editor 之 编辑器选项

    Delphi Code Editor 之 编辑器选项 可从Code Editor的右键菜单中选择“Properties”菜单项来查看编辑器选项.也可以从主菜单[Tools | Editor Optio ...

  8. Delphi使用ADO进行数据库编程

    Delphi是一个可视化的编程工具,ADO编程也是这样,所以话不多言,直接通过代码.截图和语言来说明. 我的数据库是Oracle,为了测试,先建一个表:create table practice(un ...

  9. 怎么使用Delphi获取当前的时间,精确到毫秒

    先介绍一个可能比较常用的方法,获取当前时间 var datetime: string; begin datetime:= FormatDateTime('yyyy-mm-dd hh:mm:ss', N ...

随机推荐

  1. CentOS7 修复grub.cfg文件

    为了达到实验目的,首先删除grub.cfg文件 重启后发现系统进不去了,这正是我们想要的 进入系统救援模式,通过输入以下命令修复grub.cfg文件 重启后发现能正常引导进入系统了

  2. JDK8 parallelStream性能测试

    https://blog.csdn.net/u011870280/article/details/80700993 public static void main(String[] args) {lo ...

  3. UVA-10462.Is There A Second Way Left(Kruskal+次小生成树)

    题目链接 本题大意:这道题用Kruskal较为容易 参考代码: #include <cstdio> #include <cstring> #include <vector ...

  4. mysql-介绍、下载安装以及软件基本管理

    一.mysql介绍 mysql是一个关系型数据库管理系统,它是一个基于socket编写的C/S架构的软件. 客户端软件: mysql自带:如mysql命令,mysqldump命令等. python模块 ...

  5. P3064 [USACO12DEC]伊斯坦布尔的帮派 (模拟)

    题目传送门 题意: 一片草地,每次可以只可以让一种牛占领,问你怎样安排牛的次序 最后剩下的是1号牛,并且输出其数量 思路: 看到n到100 ,所以可以(n^3)暴力,第一重遍历次序,第二枚举是哪只牛 ...

  6. 纯css实现网上商城左侧垂直商品分类菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. nodejs npm资料

    安装淘宝的 cnpm : npm install --global cnpm 不想安装 cnpm  又想使用淘宝的服务器来下载 : npm install jquery --registry=http ...

  8. 初学Java 数组统计字母

    public class CountLetterInArray { public static void main(String[] args) { char[] chars = createArra ...

  9. eclipse的代码格式化的个性配置

    1.安装jdk a. 到http://www.oracle.com/technetwork/java/javase/downloads/index.html 下载对应版本的jdk,安装到自己电脑上. ...

  10. [python 学习] 编码

    一.源文件编码(encoding: utf-8) 1. python 2.x 默认按ascii编码读取源文件,源码中出现了ascii不能表示的字符 "的",所以报错(3.x版本不报 ...