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;

原文地址:https://www.cnblogs.com/hnxxcxg/p/9929330.html