delphi http server
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的更多相关文章
- Delphi RAD Server 应用服务基础平台
RAD Server是一个应用服务框架平台,可快速构建和部署应用服务.RAD Server提供自动化的Delphi和C++ REST/ JSON API的 发布与管理.企业数据库集成中间件.智能物联网 ...
- 自动创建数据库(DELPHI+SQL SERVER)
procedure TForm1.Btn_OKClick(Sender: TObject); var sqlconn:string; begin Sqlconn:='Provider=SQLOLEDB ...
- ODBC连接发生错误:未发现数据源名称并且未指定默认驱动程序
程序在使用ODBC方式连接数据库时发生错误: ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序. 什么原因造成的呢? 本人使用&l ...
- 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 ...
- 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 ...
- Python 列表(List)
列表是最常用的Python数据类型,它可以作为一个方括号内的逗号分隔值出现. 列表的数据项不需要具有相同的类型. 一.列表定义 用逗号分隔不同的数据项使用方括号括起来. >>> li ...
- delphi 2010 导出sql server 数据到DBF乱码问题
近日,由于业务需要导出sql server 数据到DBF文件,要查询多表记录,并适当处理后生成导出DBF文件,系统使用delphi2010平台开发. 首先按要求在VFP里创建DBF表,字段数有240个 ...
- delphi xe5 android 开发数据访问server端(二)
上一篇我们创建了一个拟给手机端访问的webservices服务 接下来创建一个返回数据集的过程,用webservices发布,供手机端调用.这里我使用firedac 1.打开上一篇自动创建的WebMo ...
- Delphi动态配置ODBC数据源--SQL Server版本
(摘自)http://jxlearnew.blog.163.com/blog/static/549786592007102451431413/ 这里介绍一种用Delphi来实现动态注册的方法,希望对各 ...
随机推荐
- mysql批量插入更新操作
//添加关联赠品(确定) public function addGiveGoods($ids,$child,$parent_sku_no){ $license=new LicenseModel(); ...
- lvs负载均衡配置
三台server的ip direct_server:192.168.248.128 real_server1:192.168.248.130 real_server2:192. ...
- django ajax发送post请求
第一种:将csrf_token放在from表单里 <script> function add_competion_goods() { $.ajax({ url: "{% url ...
- 5 GC 参数
- 机器学习-liuyubobobo(慕课网)
第一章 python3玩转机器学习 第二章 机器学习基础 安装:1.anaconda 2.pycharm 第三章 Jupyter Notebook,numpy,Matplotlib 1.jupyt ...
- NASA航天技术演示实验集
为了支持太空探索NASA开起了一系列先进太空技术演示实验. 具体的实验实验地址在:https://www.nasa.gov/mission_pages/tdm/main/overview.html 通 ...
- POJ 3614:Sunscreen 贪心+优先队列
Sunscreen Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5378 Accepted: 1864 Descrip ...
- fiddler 限速方法
1.使用的软件下载地址: \\192.168.100.2\共享软件\开发常用\flash_team\工作软件\fiddler2setup.exe 2.注意事项 测试是,在ie浏览器环境下测试 3.软件 ...
- 指令——free
free指令 一个完整的指令的标准格式: Linux通用的格式——#指令主体(空格) [选项](空格) [操作对象] 一个指令可以包含多个选项,操作对象也可以是多个. free指令作用:查看内存使用情 ...
- java枚举类(转)
转自: http://blog.sina.com.cn/s/blog_697b968901013ih1.html 这里主要讲解的是Java的枚举类型 什么是枚举? 以我的理解答:枚举是我们自己定义的一 ...