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. Java笔记--异常

    1.异常分为两类: --1)Error:Java虚拟机无法解决的严重问题(例如资源耗尽等): --2)Exception:其他编程错误或偶然的外在因素导致的一般性问题(例如空指针异常.读取的文件不存在 ...

  2. Linux基础命令、软件安装

    常用命令 查看当前系统中存在哪些shell cat /etc/shells [root@** ~]# cat /etc/shells /bin/sh /bin/bash /usr/bin/sh /us ...

  3. IDE及PHP基础——注释、变量、数据、运算符、输出等

    IDE(Integrated Development Environment ),集成开发环境,是用于提供程序开发环境的应用程序,一般包括代码编辑器.编译器.调试器和图形用户界面等工具.集成了代码编写 ...

  4. python实现二分法

    前言: 二分法主要是用来查找位置的id,每次能够排除掉一半的数据,查找的效率非常高,但是局限性比较大. 必须是有序序列才可以使用二分查找. 原理 首先,假设表中元素是按升序排列,将表中间位置记录的关键 ...

  5. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):带有字体图标的导航栏

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. 剑指offer自学系列(五)

    题目描述:请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g".当从该字符流中读出 ...

  8. c++输出哈夫曼编码

    #include<iostream> #include<string> using namespace std; struct huffTree { int parent; i ...

  9. Vulkan SDK 之Render Pass

    Create a Render Pass A render pass describes the scope of a rendering operation by specifying the co ...

  10. Spring-IOC(基于注解)

    1.Spring 的 Bean 管理:(注解方式) 1.1 创建 web 项目,引入 Spring 的开发包: 注:在 Spring 的注解的 AOP 中需要引入 spring-aop 的 jar 包 ...