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. js转换后台接受的日期格式

    var html = "--";if(data.createTime!=null&&data.createTime!=""){ Date.pro ...

  2. 日记smarthome

    测试命令:测试命令 7e 7e 两个字节 一个字节  两个字节 一个字节     解释: 两个字节是userid的值 int Userid = data[i] * 256 + data[i + 1]; ...

  3. [AHOI2013]作业 (莫队+分块)

    [AHOI2013]作业 (莫队+分块) 题面 给定了一个长度为n的数列和若干个询问,每个询问是关于数列的区间[l,r],首先你要统计该区间内大于等于a,小于等于b的数的个数,其次是所有大于等于a,小 ...

  4. poj1305 Fermat vs. Pythagoras(勾股数)

    题目传送门 题意: 设不定方程:x^2+y^2=z^2若正整数三元组(x,y,z)满足上述方程,则称为毕达哥拉斯三元组.若gcd(x,y,z)=1,则称为本原的毕达哥拉斯三元组. 定理:正整数x,y, ...

  5. 固定标签(position: fixed)

    document.body.scrollTop 要改成 document.documentElement.scrollTop不然不生效 <!DOCTYPE html> <html l ...

  6. 第一个progressive web application,发车!

    progressive web application是谷歌推出的一种渐进式web应用,通过利用service-worker等来达到类似于原生应用,而且在chrome浏览器还可以添加到主页,完全就和一 ...

  7. linux下查看Apache的访问日志及ip

    linux下查看Apache的实时访问日志:tail -f  /etc/httpd/logs/access_log 查看有哪些ip访问过:cat access_log |awk '{print $1} ...

  8. mysql 乐观锁、悲观锁、共享锁,排它锁

    mysql锁机制分为表级锁和行级锁,本文就和大家分享一下我对mysql中行级锁中的共享锁与排他锁进行分享交流. 共享锁又称为读锁,简称S锁,顾名思义,共享锁就是多个事务对于同一数据可以共享一把锁,都能 ...

  9. CSS多列布局(栅格布局)

    一.多列布局 CSS3 可以将文本内容设计成像报纸一样的多列布局,如下实例: 代码如下(具体的解释也在代码中)浏览器支持表格中的数字表示支持该方法的第一个浏览器的版本号. 紧跟在数字后面的 -webk ...

  10. Zabbix分布式监控系统实践

    https://www.zabbix.com/wiki/howto/install/Ubuntu/ubuntuinstall 环境介绍OS: Ubuntu 10.10 Server 64-bitSer ...