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;
總結
以上是生活随笔為你收集整理的idhttpserver的使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 保存/恢复cxGrid布局
- 下一篇: 使用python连接数据库