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来实现动态注册的方法,希望对各 ...
随机推荐
- Day8 - D - Multiplication Table CodeForces - 448D
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the mu ...
- 07.swoole学习笔记--tcp客户端
<?php //创建tcp客户端 $client=new swoole_client(SWOOLE_SOCK_TCP); //连接服务器 $client->connect(,) or di ...
- 应用于Oculus Quest的VR头显应用
项目需要一个VR头显项目来展示算法成果,设备为Oculus Quest一体机,基于android平台(平台要切换为android),体验了下设备效果还行,但还是有点沙窗效应.记录一下开发流程. 先贴个 ...
- J. Cola
J. Cola time limit per test 4.0 s memory limit per test 64 MB input standard input output standard o ...
- chatdet用法
1. 下载chardet 2. 在命令提示符里转到chardet的存放目录,执行python setup.py install 3. 在代码中用 import chardet 导入模块 4. 用法:c ...
- 解决dispatch 后在当前页面不能获取最新的this.props中的数据
因为dispatch为异步方法 .解决这个问题方法很多 出去添加定时器这种不是很优雅的方法 我们可以用 componentWillReceiveProps(nextProps) 这个生命周期 ...
- 137-PHP static修饰的类属性
<?php class test{ //定义一个类 public static $num=0; //定义static修饰的类属性 public function __construct(){ / ...
- Python 比较 相等性 真值
1 == 操作符测试 值 的相等性: is 测试对象的一致性.注意短字符串的is相等性测试,PVM会缓存短字符串,s1 is s2 将返回true. 2 false:"", [], ...
- 留学Essay写作关键:Intensive Reading
留学生的日常除了写写写还是写写写,有时候还是要换换口味.在自己没有作业压力的时候可以尝试去读一些相关书籍或者一些优秀的essay.当然了,这里的阅读可不是走马观花,囫囵吞枣的读,而是用心去“精读”.那 ...
- MySQL5.7忘记密码解决方案
第一种方法 首先是网上普遍见到的 关闭服务 windows下在C:\ProgramData(隐藏文件夹)\MySQL\MySQL Server 5.7\my.ini中的[mysqld]下添加skip- ...