RealThinClient SDK是用于开发标准的HTTP(S)服务器,ISAPI扩展以及客户端的VCL控件。可用于Windows下的CodeGear Delphi 6-2010。关于RealThinClient SDK的教程会持续更新,本节是RealThinClient SDK的第二课,如何使用构建的服务器发送动态生成的内容。浏览器
本教程将展现在知道如何建立Web服务器以及如何发送动态生成的内容后,如何接受查询参数。咱们将对咱们以前的代码(演示发送动态生成内容的代码)进行一些小的更改,以接受请求的查询参数。 服务器
在以前编写动态生成的内容时,是没有选择让用户决定系统将返回哪一个Square值的,因此接下来须要选择Square值的起始编号和结束数字。 并发
接下来看一下具体的操做步骤:ide
打开咱们的第2课项目。ui
编辑RtcDataProvider组件的OnDataReceived事件 spa
浏览器的Square请求地址栏中的URL是:http:// localhost / square,如今须要传递两个参数,即起始和结束数字,以返回Squared值。修改网址以下:http://localhost/square?start=10&end=20code
再发送两个查询参数start和end。这里必须采起一些措施来防止内容增加并致使拒绝服务或出现更糟糕的状况。(注意:能够经过检查请求的平方数是否超过1,000来防止这种状况发生)。 若没有开始或结束查询参数会,就要为每一个查询参数设置一个默认值,这样服务器运行时就不会出现错误。可是,仍是须要向用户通知此类问题。orm
使用withcdn
procedure TForm1.rdpSquareDataReceived(Sender: TRtcConnection); var viLine : integer; viStart, viEnd : integer; vbStartError, vbEndError, vbRangeError : boolean;begin with TRtcDataServer(Sender) do begin if Request.Complete then begin viStart := 1; viEnd := 100; vbStartError := True; vbEndError := True; vbRangeError := True; if Request.Query['start'] <> '' then try viStart := StrToInt(Request.Query['start']); vbStartError := False; except end; if Request.Query['end'] <> '' then try viEnd := StrToInt(Request.Query['end']); vbEndError := False; except end; if viEnd - viStart > 1000 then viEnd := viStart + 100 else vbRangeError := False; Write(''); Write('Square Values'); if vbStartError = True then Write('ERROR: Wrong start parameter. Set to Default (1)'); if vbEndError = True then Write('ERROR: Wrong end parameter. Set to Default (100)'); if vbRangeError = True then Write('ERROR: Wrong Range. Set to Default (100)'); Write('NumberSquare'); for viLine := viStart to viEnd do begin Write('' + IntToStr(viLine) + ''); Write('' + IntToStr(viLine * viLine) + ''); end; Write(''); end; end;end;复制代码
不使用with
procedure TForm1.rdpSquareDataReceived(Sender: TRtcConnection); var viLine : integer; rdsServer : TRtcDataServer absolute Sender; viStart, viEnd : integer; vbStartError, vbEndError, vbRangeError : boolean;begin if rdsServer.Request.Complete then begin viStart := 1; viEnd := 100; vbStartError := True; vbEndError := True; vbRangeError := True; if rdsServer.Request.Query['start'] <> '' then try viStart := StrToInt(rdsServer.Request.Query['start']); vbStartError := False; except end; if rdsServer.Request.Query['end'] <> '' then try viEnd := StrToInt(rdsServer.Request.Query['end']); vbEndError := False; except end; if viEnd - viStart > 1000 then viEnd := viStart + 100 else vbRangeError := False; rdsServer.Write(''); rdsServer.Write('Square Values'); if vbStartError = True then rdsServer.Write('ERROR: Wrong start parameter. Set to Default (1)'); if vbEndError = True then rdsServer.Write('ERROR: Wrong end parameter. Set to Default (100)'); if vbRangeError = True then rdsServer.Write('ERROR: Wrong Range. Set to Default (100)'); rdsServer.Write('NumberSquare'); for viLine := viStart to viEnd do begin rdsServer.Write('' + IntToStr(viLine) + ''); rdsServer.Write('' + IntToStr(viLine * viLine) + ''); end; rdsServer.Write(''); end;end;复制代码
检查两个查询参数(start和end),若是没有此参数的数据,将会使用默认值(1表示start,100表示end)。而后检查范围(end减去start)是否大于1,000,若是是,则将其设置为100。若是任这类何检查失败,咱们都会向用户发送错误消息。
检查服务器是否正在运行并发送正确响应。
接下来运行应用程序:
在浏览器中输入如下任一地址:
http://localhost/square?start=10&end=200
http://localhost/square
http://localhost/square?start=-15
http://localhost/square?start=helloworld
浏览器显示画面以下:
本教程中附带的资源: