TIdHTTPServer 应用小例子
只处理了get的请求,没有对参数进行细分,反正有参数就可以了。
idhtpsrvr1: TIdHTTPServer;
port :Integer;
idhtpsrvr1.DefaultPort:=port; idhtpsrvr1.Active:=true; if idhtpsrvr1.Active then self.Log('监听服务启动成功 端口是'+inttostr(port), '', 2) else self.Log('监听服务启动失败 端口是'+inttostr(port), '', 2); //------------------用 procedure TFrmMain.idhtpsrvr1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo); var sReqContext : string; begin try //Post方式获取请求内容 if ARequestInfo.Command = 'POST' then begin //获取请求串 sReqContext := ARequestInfo.FormParams; // 请求串为空,退出 if Trim(sReqContext) = '' then Exit; //解析请求串 //ParseRequest(sReqContext); //处理请求 //GetReply(sReqContext); end else begin //获取请求串 sReqContext := ARequestInfo.QueryParams; // 请求串为空,退出 if Trim(sReqContext) = '' then begin //AResponseInfo.ContentText:='请求参数不能为空,请联系技术'; Exit; end else begin //处理请求
AResponseInfo.ContentType:='text/json;charset=utf-8';
if not self.ProcessTheData2(DateOf(dtpStarTime.DateTime) + Timeof(Now)) then begin AResponseInfo.ContentText:='执行失败,请联系技术';end else begin AResponseInfo.ContentText:='执行成功了,参数是'+sReqContext;end; end; end; except on E: Exception do begin AResponseInfo.ContentText:='执行异常,请联系技术'; end; end; end;
请求地址 http://localhost:8085/?aas=dd
192.192.211.**:35011/?aas=dd

浙公网安备 33010602011771号