idhttpserver的使用方法

idhttpserver的使用方法

1)CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);事件

該事件和IDTCPSERVER的EXECUTE()事件一樣,都是“線程方法”,即事件是在子線程裏面執行的,在其內書寫代碼要注意“線程保護”。

該事件可以接受客戶端HTTP GET、POST或其他HTTP方法請求。

if SameText(ARequestInfo.Command, 'post') then    // http post方法

else if SameText(ARequestInfo.Command, 'get') then    // http get方法

2)獲取URL參數

ARequestInfo.Params.Values['sql']

3)回覆客戶端

回覆客戶端流

AResponseInfo.ContentStream := LFiredac.QuerySQL(ARequestInfo.Params.Values['sql'], ARequestInfo.Params.Values['storageformat']);  // 流
AResponseInfo.WriteContent;

回覆客戶端字符串

AResponseInfo.ContentText := LFiredac.SaveData(ARequestInfo.Params.Values['tablename'], ARequestInfo.PostStream, ARequestInfo.Params.Values['storageformat']);
AResponseInfo.WriteContent;

4)回覆客戶端中文字符串不亂碼

AResponseInfo.ContentText := LFiredac.RestQuery(ARequestInfo.Params.Values['sql']);
AResponseInfo.ContentType := 'text/html; charset=GB2312';
AResponseInfo.WriteContent;

5)PostStream(AContext: TIdContext; AHeaders: TIdHeaderList; var VPostStream: TStream);事件

如果要接受客戶端發過來的流,則在此事件中要寫如下代碼:

begin
VPostStream := TMemoryStream.Create; 
end;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章