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)CreatePostStream(AContext: TIdContext; AHeaders: TIdHeaderList; var VPostStream: TStream);事件

如果要接受客户端发过来的流,则在此事件中要写如下代码:

begin
VPostStream := TMemoryStream.Create; 
end;

posted @   delphi中间件  阅读(7771)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示