翻譯|使用教程|編輯:況魚杰|2019-07-04 10:58:49.397|閱讀 381 次
概述:本教程將展示在知道如何創建Web服務器以及如何發送動態生成的內容后,如何接受查詢參數。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
RealThinClient SDK是用于開發標準的HTTP(S)服務器,ISAPI擴展以及客戶端的VCL控件。可用于Windows下的CodeGear Delphi 6-2010。關于RealThinClient SDK的教程會持續更新,本節是RealThinClient SDK的第三課,如何使用參數查詢的服務器。
本教程將展示在知道如何創建Web服務器以及如何發送動態生成的內容后,如何接受查詢參數。我們將對我們之前的代碼(演示發送動態生成內容的代碼)進行一些小的更改,以接受請求的查詢參數。
在之前編寫動態生成的內容時,是沒有選擇讓用戶決定系統將返回哪個Square值的,所以接下來需要選擇Square值的起始編號和結束數字。
接下來看一下具體的操作步驟:
打開我們的第2課項目。
編輯RtcDataProvider組件的OnDataReceived事件
瀏覽器的Square請求地址欄中的URL是:http:// localhost / square,現在需要傳遞兩個參數,即起始和結束數字,以返回Squared值。修改網址如下://localhost/square?start=10&end=20
再發送兩個查詢參數start和end。這里必須采取一些措施來防止內容增長并導致拒絕服務或出現更糟糕的情況。(注意:可以通過檢查請求的平方數是否超過1,000來防止這種情況發生)。 若沒有start或end查詢參數,就要為每個查詢參數設置一個默認值,這樣服務器運行時就不會出現錯誤。但是,還是需要向用戶通知此類問題。
使用with
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。如果任這類何檢查失敗,我們都會向用戶發送錯誤消息。
檢查服務器是否正在運行并發送正確響應。
接下來運行應用程序:
在瀏覽器中輸入以下任一地址:
//localhost/square?start=10&end=200
//localhost/square
//localhost/square?start=-15
//localhost/square?start=helloworld
瀏覽器顯示畫面如下:
本教程中附帶的資源:
RealThinClient SDK - DEMO第3課 - 使用查詢參數PDF
在慧都科技,能夠為您的企業找到解決方案,還有企業IT相關培訓,以及計算機軟件/硬件的銷售,想要了解更多有關慧都的資訊,請點擊,或者關注慧都微信公眾號 ???
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: