unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdContext, IdCustomHTTPServer,
Vcl.StdCtrls, IdBaseComponent, IdComponent, IdCustomTCPServer, IdHTTPServer; type
TForm1 = class(TForm)
IdHTTPServer1: TIdHTTPServer;
btnStart: TButton;
btnStop: TButton;
edtIp: TEdit;
edtPort: TEdit;
edtRootDir: TEdit;
lbl1: TLabel;
lbl2: TLabel;
lbl3: TLabel;
edtIndex: TEdit;
mmo1: TMemo;
procedure btnStartClick(Sender: TObject);
procedure btnStopClick(Sender: TObject);
procedure IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} //uses IdGlobal; //IndyTextEncoding_UTF8 var
RootDir:string;
URL:string; procedure TForm1.btnStopClick(Sender:TObject);
begin
IdHTTPServer1.Active:=false;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
edtip.Text:= '127.0.0.1';
edtport.Text:= '';
edtIndex.Text:= 'a.txt'; btnStartClick(btnstart);
end; procedure TForm1.btnStartClick(Sender:TObject);
begin
if IdHTTPServer1.Active then exit; try
IdHTTPServer1.Bindings.Clear;
//要绑定的端口,一定设置此项,这是真正要绑定的端口;
IdHTTPServer1.DefaultPort:=strtoint(trim(edtport.Text));
IdHTTPServer1.Bindings.Add.IP:=trim(edtip.Text);
//启动服务器
IdHTTPServer1.Active:=True;
except
showmessage('启动失败!');
end; //RootDir:=trim(edtrootdir.Text);
rootdir:= ExtractFilePath(Application.ExeName);
URL:='http://'+trim(edtip.Text)+trim(edtport.Text)+'/';
//浏览器请求http://127.0.0.1:8008/index.html?a=1&b=2
end; procedure TForm1.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过来的数据 //1 获取参数
// mmo1.Lines.Clear;
// mmo1.Lines.Add(ARequestInfo.Document) ;
// mmo1.Lines.Add(arequestinfo.Params.Values['a']) ;
// mmo1.Lines.Add(arequestinfo.Params.Values['b']); //2 webserver发文件
// LFilename := ARequestInfo.Document;
// if LFilename = '/' then
// begin
// LFilename := '/'+trim(edtIndex.Text);
// end;
// LPathname := RootDir + LFilename;
// if FileExists(LPathname) then
// begin
// AResponseInfo.ContentStream := TFileStream.Create(LPathname, fmOpenRead + fmShareDenyWrite);//发文件
// end
// else
// begin
//
// AResponseInfo.ContentType := 'text/html; charset=GB2312';
// AResponseInfo.ResponseNo := 404;
// AResponseInfo.ContentText := '找不到' + ARequestInfo.Document;
// //找不到,这三个汉字显示为乱码,算个bug
// end; //3 发html文件
// AResponseInfo.ContentType := 'text/html; charset=GB2312';
// // AResponseInfo.WriteContent;
// AResponseInfo.ContentText:='<html><body>dsddddd你好哈哈哈好</body></html>'; //4发xml文件
AResponseInfo.ContentType :='text/xml;charset=GB2312';
AResponseInfo.ContentText:='<?xml version="1.0" encoding="utf-8"?>'
+'<students>'
+'<student sex = "male"><name>'+'陈'+'</name><age>14</age></student>'
+'<student sex = "female"><name>bb</name><age>16</age></student>'
+'</students>'; //5下载文件时,直接从网页打开而没有弹出保存对话框的问题解决 indy10貌似没有这个问题
{AResponseInfo.CustomHeaders.Values['Content-Disposition'] :='attachment;
filename="'+文件名+'"';
}
//AResponseInfo.ServeFile(AContext,'a.txt');
//仅这一句即可下载并弹框 //6替换 IIS
// AResponseInfo.Server:='IIS/6.0';
// AResponseInfo.CacheControl:='no-cache';
// AResponseInfo.Pragma:='no-cache';
// AResponseInfo.Date:=Now; end; end.

delphi http server的更多相关文章

  1. Delphi RAD Server 应用服务基础平台

    RAD Server是一个应用服务框架平台,可快速构建和部署应用服务.RAD Server提供自动化的Delphi和C++ REST/ JSON API的 发布与管理.企业数据库集成中间件.智能物联网 ...

  2. 自动创建数据库(DELPHI+SQL SERVER)

    procedure TForm1.Btn_OKClick(Sender: TObject); var sqlconn:string; begin Sqlconn:='Provider=SQLOLEDB ...

  3. ODBC连接发生错误:未发现数据源名称并且未指定默认驱动程序

    程序在使用ODBC方式连接数据库时发生错误: ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序. 什么原因造成的呢? 本人使用&l ...

  4. Writing a Windows Shell Extension(marco cantu的博客)

    Writing a Windows Shell Extension This is a technical article covering the content of my last week s ...

  5. Kitto2 now with free opensource Kide2 since September 2017(提供Web解决方案,大概是觉得Mobile开发快差不多了)

    Kitto2 is a tool for data-driven web application Development. It allows to create Rich Internet Appl ...

  6. Python 列表(List)

    列表是最常用的Python数据类型,它可以作为一个方括号内的逗号分隔值出现. 列表的数据项不需要具有相同的类型. 一.列表定义 用逗号分隔不同的数据项使用方括号括起来. >>> li ...

  7. delphi 2010 导出sql server 数据到DBF乱码问题

    近日,由于业务需要导出sql server 数据到DBF文件,要查询多表记录,并适当处理后生成导出DBF文件,系统使用delphi2010平台开发. 首先按要求在VFP里创建DBF表,字段数有240个 ...

  8. delphi xe5 android 开发数据访问server端(二)

    上一篇我们创建了一个拟给手机端访问的webservices服务 接下来创建一个返回数据集的过程,用webservices发布,供手机端调用.这里我使用firedac 1.打开上一篇自动创建的WebMo ...

  9. Delphi动态配置ODBC数据源--SQL Server版本

    (摘自)http://jxlearnew.blog.163.com/blog/static/549786592007102451431413/ 这里介绍一种用Delphi来实现动态注册的方法,希望对各 ...

随机推荐

  1. gem5-gpu 全系统FS模式 系统调用SE模式

    SE模式中无线程调度器,只能运行单线程程序,如SPEC CPU 2006,仅模拟片上CPU.GPU.Network和DRAM等. FS模式需加载虚拟Linux和磁盘,Linux负责线程调度.实现了Pt ...

  2. 二、Vue组件(component):组件的相互引用、通过props实现父子组件互传值

    一.组件各部分说明及互相引用 1.一个vue组件由三个部分组成 Template 只能存在一个根元素 2.Script 3.Style scoped:样式只在当前组件内生效 1.1 组件的基本引用代码 ...

  3. DevOps - 与敏捷方法区别

    章节 DevOps – 为什么 DevOps – 与传统方式区别 DevOps – 优势 DevOps – 不适用 DevOps – 生命周期 DevOps – 与敏捷方法区别 DevOps – 实施 ...

  4. 将.py文件转化成.exe

    机子上已经安装好python,且配置好环境变量 编写好xx.py文件 安装pywin32.此处一定注意pywin32有32位和64位之分.可以在命令提示符里输入python来查看python的版本以及 ...

  5. POJ 1565:Skew Binary

    Skew Binary Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10676   Accepted: 6807 Desc ...

  6. netty权威指南学习笔记四——TCP粘包/拆包之粘包问题解决

    发生了粘包,我们需要将其清晰的进行拆包处理,这里采用LineBasedFrameDecoder来解决 LineBasedFrameDecoder的工作原理是它依次遍历ByteBuf中的可读字节,判断看 ...

  7. mapper.xml实现oracle的分页语句

    当我们用常规方法进行分页查询时,虽然在数据库可以分页查询出来数据, 如下语句 <!-- 分页查询所有 --> <select id="findAllPage" r ...

  8. 四、JavaScript之<script>标签的使用

    一.代码如下 二.运行效果如下 <!DOCTYPE html> <html> <meta http-equiv="Content-Type" cont ...

  9. 吴裕雄--天生自然C++语言学习笔记:C++ 多态

    多态按字面的意思就是多种形态.当类之间存在层次结构,并且类之间是通过继承关联时,就会用到多态. C++ 多态意味着调用成员函数时,会根据调用函数的对象的类型来执行不同的函数. 下面的实例中,基类 Sh ...

  10. vue学习(十)mixin 偷懒

    一 mixin混入偷懒技术 架子 <div id="app"> {{msg}} </div> <script> let app = new Vu ...