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. 无法识别的配置节 system.webServer

    Web.config文件里面加入 <configSections> <section name="system.webServer" type="Sys ...

  2. hbase hbck及region RIT处理

    hbase hbck主要用来检查hbase集群region的状态以及对有问题的region进行修复. hbase hbck :检查hbase所有表的一致性,如果正常,就会Print OK hbase ...

  3. Tornadao Cookie

    cookie的详细介绍.Tronado带签名的cookie原理.基于cookie实现用户验证 cookie详细介绍 cookie本质就是存于浏览器的 键值对. 特性: 每次http请求服务端的时候,都 ...

  4. Fréchet Inception Distance(FID)

    计算 IS 时只考虑了生成样本,没有考虑真实数据,即 IS 无法反映真实数据和样本之间的距离,IS 判断数据真实性的依据,源于 Inception V3 的训练集 ------ ImageNet,在 ...

  5. dedecms 栏目目录用首字母生成的方法

    修改dede/catalog.add.php文件 85行 $toptypedir = GetPinyin(stripslashes($toptypename)); 修改为 $toptypedir = ...

  6. 【踩坑记录】记录一次使用Python logging库多进程打印日志的填坑过程

    背景: 项目使用Python自带的logging库来打印日志 项目部署在一台Centos7的机器上 项目采用gunicorn多进程部署 过程: 1.LOG日志代码封装: 采用logging库,并设置w ...

  7. 13 装备的添加和移除(Unity3D)

    本案例主要实现功能如下:1.创建UI界面,包含两个装备栏,四个武器选择栏以及显示人物的属性的文本框2.每一个装备都有自己的属性(AD/AP/AR/MP)3.人物也有自己的基础属性(AD/AP/AR/M ...

  8. 关于c++静态类的说法

    看了网上的观点,大致有这几种比较好的. 观点一:根据现代的C++观点,静态类没有必要存在于C++中. 一个类是对一个概念的描述,类的本质是它维护了一个不变式,也就是说它有一个状态,它所有的接口都是为了 ...

  9. linux下软件包的安装方式

    参考:https://blog.51cto.com/13589255/2071277

  10. 51nod 1429:巧克力

    1429 巧克力 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 现在有两个块巧克力一块大小是   的,另外一块大 ...