惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - 万一

关于内存数据与 JSON 高亮 TRichEdit 当前行 使用 IntraWeb (45) - 活用 IntraWeb 使用 IntraWeb (44) - 测试读取 SqLite (三) 使用 IntraWeb (43) - 测试读取 SqLite (二) 使用 IntraWeb (42) - 测试读取 SqLite (一) 使用 IntraWeb (41) - 数据控件速查 使用 IntraWeb (40) - 自定义 Session 数据 使用 IntraWeb (38) - TIWAppForm、TIWForm、TIWBaseHTMLForm、TIWBaseForm 使用 IntraWeb (37) - TIWApplication 使用 IntraWeb (36) - TIWServerControllerBase 使用 IntraWeb (35) - TIWJQueryWidget - 万一 使用 IntraWeb (34) - TIWAJAXNotifier 使用 IntraWeb (33) - Cookie 使用 IntraWeb (32) - Url 映射与 THandlers 使用 IntraWeb (31) - IntraWeb 的 Xml 操作使用的是 NativeXml - 万一 使用 IntraWeb (30) - TIWAppInfo、TIWMimeTypes、TIWAppCache - 万一 使用 IntraWeb (29) - 基本控件之 TIWAutherList、TIWAutherINI、TIWAutherEvent - 万一 使用 IntraWeb (28) - 基本控件之 TIWTemplateProcessorHTML、TIWLayoutMgrHTML、TIWLayoutMgrForm
使用 IntraWeb (39) - THttpRequest、THttpReply
万一 · 2014-06-27 · via 博客园 - 万一

在其它服务器脚本语言中熟悉的 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);
begin
  WebApplication.GoToURL('Page2.html?AAA=111&BBB=222');
end;

{Unit2 中的关键代码}
procedure TIWForm2.IWAppFormURLRequest(aSender: TIWAppForm; aRequest: THttpRequest); //需 uses IW.HTTP.Request
begin
  IWMemo1.Lines.Add(WebApplication.Request.QueryFields.Values['bbb']);
end;

initialization
  TIWForm2.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_2

property 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_2

property 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 = TRUE

constructor 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;

interface

uses Classes, IW.Content.Base, HTTPApp, IWApplication, IW.HTTP.Request, IW.HTTP.Reply, IWMimeTypes;

type
  TMyIndex = class(TContentBase)
  protected
    function Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication; aParams: TStrings): Boolean; override;
  public
    constructor Create; override;
  end;

implementation

{ TMyIndex }

constructor TMyIndex.Create;
begin
  inherited;
  mFileMustExist := False;
end;

function TMyIndex.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication; aParams: TStrings): Boolean;
begin
  aReply.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}
uses
  IWInit, IWGlobal, IW.Content.Handlers, MyIndex;

procedure TIWServerController.IWServerControllerBaseConfig(Sender: TObject);
begin
  THandlers.AddStartHandler('', 'Index.htm', TMyIndex.Create);
end;