在其它服务器脚本语言中熟悉的 Request、Response(THttpRequest、THttpReply) 在 IntraWeb 中算是幕后英雄了, 用户基本不需要直接操作它们了.

IW 默认 Post 传值(WebApplication.Request.HttpMethod = hmPost, 只读), 但像表单字段之类, 在 IW 中直接根据控件名称读取就是了, 用不着麻烦 Request.
但如果需要, 可以使用 WebApplication.Request.QueryFields.Values['控件名'] 读取.

要读出以 Get 方式传输的 Url 变量, 发现在很多时候 WebApplication.Request.QueryFields.Values['变量名'] 并不好用; 经过尝试, 也不是没有办法:
1、笨办法: 自己解析 WebApplication.Request.Referer;
2、Request 以参数方式出现时往往可以, 譬如 TIWAppForm.OnURLRequest 事件:


{Unit1 中的关键代码}
procedure TIWForm1.IWButton1Click(Sender: TObject);
beginWebApplication.GoToURL('Page2.html?AAA=111&BBB=222');
end;{Unit2 中的关键代码}
procedure TIWForm2.IWAppFormURLRequest(aSender: TIWAppForm; aRequest: THttpRequest); //需 uses IW.HTTP.Request
beginIWMemo1.Lines.Add(WebApplication.Request.QueryFields.Values['bbb']);
end;initializationTIWForm2.SetURL('', 'Page2.html');


我想, 按照 IW 的理念, 网页间互相传递的参数应该是用 Session(下篇博客测试下).



有时还要用到运行参数, 输入运行参数有两种方法:
1.从代码(如: WebApplication.RunParams.CommaText := 'AAA=111,BBB=222');
2.从 Server 控制台(如下图);

读取运行参数, 如: MyStr := WebApplication.RunParams.Values['AAA'];



THttpRequest 所在单元及继承链:
IW.HTTP.Request.THttpRequest < TObject

主要成员(根据测试结果判断吧):


property UserAgent: string       //测试结果: Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko
property Referer: string         //测试结果: http://127.0.0.1:8888/$/?aaa=111&bbb=222; 测试时添加了两个运行参数
property ScriptName: string      //
property Host: string            //测试结果: 127.0.0.1
property URL: string             //
property PathInfo: string        //测试结果: /$/callback
property RemoteAddr: string      //测试结果: 127.0.0.1
property ServerPort: integer     //测试结果: 8888
property Query: string           //测试结果: callback=...
property HttpMethod: THttpMethod //测试结果: hmPost(其它: hmNone, hmGet, hmPut, hmPost, hmHead)
property IfModifiedSince: string //
property ForwardedFor: string    //
property HttpClientIP: string    //
property AcceptLanguage: string  //测试结果: zh-CN
property HttpsHeader: string     //
property Authorization: string   //
property AuthorizationHeader: string //
property AuthUser: string        //
property AuthPass: string        //
property ServerVariables: TStrings //
property HasContent: Boolean       //测试结果: True
property Files: THttpFileList      //
property QueryString: string       //测试结果: callback=...
function GetCookieValue(const aName: string): string;
function GetRawHeaderValue(const aName: string): string;
function GetServerVariableValue(const aVariableName: string): string;
function GetContentFieldValue( const aContentFieldName: string): string;
procedure SetRewriteURL(const aUrl: string);property RawHeaders: TStrings //测试结果: //Accept: */*//Content-Type: application/x-www-form-urlencoded//Referer: http://127.0.0.1:8888/$///Accept-Language: zh-CN//Accept-Encoding: gzip, deflate//User-Agent: Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko//Host: 127.0.0.1:8888//Content-Length: 205//DNT: 1//Connection: Keep-Alive//Cache-Control: no-cache//Cookie: IW_MyApp=rtDemtDbmuncnJHgndGWqueWrKmWodK1otaXrue4mdu_2property ContentFields: TStrings //测试结果://IWBUTTON2=//IW_Action=IWBUTTON2//IW_ActionParam=//IW_FormName=IWForm1//IW_FormClass=TIWForm1//IW_LocationHash=//IW_TrackID_=2//IW_width=1920//IW_height=985//IW_SessionID_=mKrbmdjendG0mZLgndGXoefbn0yWoefbmti2rJngode//callback=IWBUTTON2.DoOnAsyncClick//x=48//y=10//which=0//modifiers=property CookieFields: TStrings  //测试结果: IW_MyApp=ourdmeffmdHgmtK1ndiWodGZoungnKvfmtG5nKiXmue_2property QueryFields: TStrings //测试结果://IWBUTTON2=//IW_Action=IWBUTTON2//IW_ActionParam=//IW_FormName=IWForm1//IW_FormClass=TIWForm1//IW_LocationHash=//IW_TrackID_=2//IW_width=1920//IW_height=985//IW_SessionID_=nZKXqtvcrJvbmtiZndjfrKe1nZm3numYmta3ruiXnZG//callback=IWBUTTON2.DoOnAsyncClick//x=52//y=18//which=0//modifiers=function GetParams: TStrings; //测试结果://IWBUTTON2=//IW_Action=IWBUTTON2//IW_ActionParam=//IW_FormName=IWForm1//IW_FormClass=TIWForm1//IW_LocationHash=//IW_TrackID_=2//IW_width=1920//IW_height=985//IW_SessionID_=nJDbrdvcrdaZnZiZndm0mJG0mem1ndnerdC1nJaWree//callback=IWBUTTON2.DoOnAsyncClick//x=56//y=15//which=0//modifiers=//IWBUTTON2=//IW_Action=IWBUTTON2//IW_ActionParam=//IW_FormName=IWForm1//IW_FormClass=TIWForm1//IW_LocationHash=//IW_TrackID_=2//IW_width=1920//IW_height=985//IW_SessionID_=nJDbrdvcrdaZnZiZndm0mJG0mem1ndnerdC1nJaWree//callback=IWBUTTON2.DoOnAsyncClick//x=56//y=15//which=0//modifiers=

THttpReply 所在单元及继承链:
IW.HTTP.Reply.THttpReply < TObject

主要成员:


property AllowCaching: Boolean //
property AuthRealm: string     //
property CacheTTL: Integer     //
property Code: Word        //
property CodeText: string      //
property ContentType: string   //
property Cookies: TCookieList //
property LastModified: TDateTime      //
property Headers: TStrings        //
property Expires: TDateTime       //
property DataType: THttpReplyType     //
property ServerPort: Integer          //
property SendingFile: Boolean         //
property CacheControlEnabled: Boolean //If FALSE, completely disable cache control header fields ("Expires", "Last-Modified", "Pragma: no-cache" and "Cache-Control: no-cache"). Default = TRUEconstructor Create(aBuffer: PByte; const aSize: Integer)
procedure Commit
procedure WriteString(const aValue: string)
procedure SendRenderStream(aStream: TIWRenderStream)
procedure SendStream(aStream: TStream; const aDisableCacheControl: Boolean)
procedure SendHsmStream(aStream: THsmStream)
procedure SendFile(const aPathname: string; aDelete: Boolean; const aDisableCacheControl: Boolean)
procedure SendCacheFile(const aPathname: string)
procedure SendRedirect(const aURL: string)
procedure ResetReplyType


学其他服务器脚本, 都快习惯了先用 Response 输出点什么, 下面测试了在 IW 中通过 Response 做简单的输出:


{新建 MyIndex 单元, 从 TContentBase 继承实现一个 TMyIndex 类}
unit MyIndex;interfaceuses Classes, IW.Content.Base, HTTPApp, IWApplication, IW.HTTP.Request, IW.HTTP.Reply, IWMimeTypes;typeTMyIndex = class(TContentBase)protectedfunction Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication; aParams: TStrings): Boolean; override;publicconstructor Create; override;end;implementation{ TMyIndex }constructor TMyIndex.Create;
begininherited;mFileMustExist := False;
end;function TMyIndex.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication; aParams: TStrings): Boolean;
beginaReply.ContentType := MIME_HTML;aReply.WriteString('<a href="http://www.cnblogs.com/del//del.cnblogs.com">万一的 Delphi 博客</a>');Result := True;
end;end. //MyIndex.pas End{在 IWServerControllerBase.OnConfig 中指定为首页, 并命名为 Index.htm}
usesIWInit, IWGlobal, IW.Content.Handlers, MyIndex;procedure TIWServerController.IWServerControllerBaseConfig(Sender: TObject);
beginTHandlers.AddStartHandler('', 'Index.htm', TMyIndex.Create);
end;

转载于:https://www.cnblogs.com/del/p/3812135.html

使用 IntraWeb (39) - THttpRequest、THttpReply相关推荐

  1. mysql修改索引语句_mysql——创建索引、修改索引、删除索引的命令语句

    查看表中已经存在 index:show index from table_name; 创建和删除索引索引的创建可以在CREATE TABLE语句中进行,也可以单独用CREATE INDEX或ALTER ...

  2. Intraweb之EasyUI篇

    Intraweb一直是Delphi快速开发web应用的首选工具,但自带的控件较少,样式比较难看,TMS与IW倒是可用,可是要收费,对于我们这些习惯用免费的用户来说,想找个破解也比较费劲.EasyUI是 ...

  3. 剑指offer:面试题39. 数组中出现次数超过一半的数字

    题目:面试题39. 数组中出现次数超过一半的数字 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字. 你可以假设数组是非空的,并且给定的数组总是存在多数元素. 示例 1: 输入: [1, ...

  4. 【蓝桥java】递归基础之39级台阶

    题目: 小明刚刚看完电影<第39级台阶>.离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级! 站在台阶前,他突然又想着一个问题: 如果我每一步只能迈上1个或2个台阶.先迈左脚,然后左 ...

  5. 使用 IntraWeb (8) - 系统模板

    我们可以自定义系统错误模板, 编辑 IWError.html 放到模板文件夹后, 它将替换默认的模板. {在主页面, 这是要模拟一个系统错误} procedure TIWForm1.IWButton1 ...

  6. 39个超实用jQuery实例应用特效

    2019独角兽企业重金招聘Python工程师标准>>> 1.Contextual Slideout:上下文滑动特效 2.Revealing Photo Slider:图片幻灯片特效 ...

  7. appium+python自动化45-夜神模拟器连不上(adb server version (36) doesn't match this client (39); killing...)...

    前言 最新下了个最新版的夜神模拟器,然后adb devices发现连不上模拟器了,报adb server version (36) doesn't match this client (39); ki ...

  8. 水母智能联合蚂蚁森林、犀牛智造等,用AI助力非遗出圈,39万人开工得“福”

    如今过年越来越有年味了,许多淡出已久的中国传统年俗,以更有趣.更年轻新潮.更科技的方式回到了大家身边.集五福.写福字.贴福字,挂福饰品,当然还有接"福袋"!人工智能实现智能设计已经 ...

  9. 3年多亏33亿,又一AI独角兽再冲刺上市,39岁天才科学家即将坐拥首个IPO?

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 来源丨AI前线 编辑丨极市平台 导读 IPO 申请"失效& ...

最新文章

  1. 手把手教你使用zabbix监控nginx
  2. STm32 使用 stm32cube GPIO 点亮 led 的
  3. Ubuntu14.04下C++程序编辑、编译、运行
  4. 【2016年第6期】情境大数据建模及其在用户行为预测中的应用
  5. detected idea启动 web_IDEA使用Tomcat服务器出现乱码问题排查过程
  6. 浅谈SkyEye虚拟ECU
  7. devc跟vc2010通用吗_王者荣耀:通用铭文大全!让你赢在起跑线上!教你1比1换铭文...
  8. ios开发学习--选项卡(Tab Bar) 效果源码分享--系列教程
  9. spring之httpclient doget请求
  10. python小技巧(初学者适用)
  11. mysql学习之mysql集群
  12. 如何解决网站可能存在webshell网页木马,阿里云网站木马后门文件提醒
  13. Java基本语法-Scanner类的应用_计算两个整数和
  14. 物流app开发需要多少钱
  15. flashpaper java_基于FlashPaper实现JSP在线阅读代码示例
  16. 常用邮箱大全,申请邮箱收费吗?邮箱活动有哪些?
  17. 互联网日报 | 贝壳找房更新IPO招股书;云闪付App用户数突破3亿;宝马近11年来首次季度亏损...
  18. Clion 的 ROS配置
  19. Linux-1:微星主板+双系统安装Ubuntu18.04.5
  20. centOS 7 安装 CUPS 打印服务器,安装映美 FP-730K打印机共享

热门文章

  1. Mr.J-- jQuery学习笔记(十八)--自定义动画
  2. springdataRedis连接redis集群
  3. 迭代器 生成器 面向过程编程
  4. 爬虫笔记八——Scrapy实战项目
  5. vsftpd安装、多用户配置
  6. 转:DotNET企业架构应用实践-架构师成长之路-如何成为优秀架构师
  7. 【李宏毅2020 ML/DL】P1 introduction
  8. HTML5 列表和表格
  9. CSMA/CD协议(一目了然,看过都说好)
  10. Dex文件格式扫描器:特征API的检测和扫描-小工具一枚(转载)