zoukankan      html  css  js  c++  java
  • Delphi Datasnap Post请求

    File- New -other


    在Form上面添加控件:

    IdHTTPServer 并实现方法IdHTTPServer1CommandGet

    procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo:
        TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    var
      ADataJson:TJSONObject;
      aRequestContent:string;
    begin
      if SameText(ARequestInfo.Document,'/api/JmzService/ExuBill') = True then
      begin
    
        if UpperCase(ARequestInfo.Command) = 'POST' THEN
        begin
      //    strPlist:= TStrings.Create();
          arequestinfo.CharSet := 'UTF-8';
    
          if  (arequestinfo.PostStream <> nil ) and (arequestinfo.PostStream.Size >0 ) then
          begin
            arequestinfo.PostStream.Position := 0;
            aRequestContent := StreamToString(ARequestInfo.PostStream);
          end;
    
          aRequestContent := TIdURI.URLDecode(aRequestContent);     //中文解码
    
      //    strPlist := ARequestInfo.Params;
    
          ADataJson:= TJSONObject.Create().AddPair('code','0').AddPair('msg','susscss').AddPair('info','测试').AddPair('token','84848ED0-A72D-4304-ADA0-001F2B7B3173');
      //    strPlist.Free;
          AResponseInfo.ContentType := 'text/html; charset=GB2312';
          AResponseInfo.CharSet := 'UTF-8';  //指定中文字符集
          AResponseInfo.ContentText:=  ADataJson.ToString;
        end;
      end
      else
      begin
       //404
          AResponseInfo.CharSet := 'UTF-8';  //指定中文字符集
          AResponseInfo.ResponseNo := 404;
    
          AResponseInfo.ContentText := '找不到' + ARequestInfo.Document;
    
      end;
    

    在启动加上

    procedure TForm1.StartServer;
    begin
      if not FServer.Active then
      begin
        FServer.Bindings.Clear;
        FServer.DefaultPort := StrToInt(EditPort.Text);
        FServer.Active := True;
        IdHTTPServer1.Active := True;//非常重要
      end;
    end;
    
    
  • 相关阅读:
    CSS实现元素居中原理解析
    Windows 下 Ionic 开发环境搭建
    JavaScript实现简单的双向数据绑定
    JavaScript之Promise对象
    前端工程师的进阶之路
    前端开发必备之chrome插件
    Javascript之Event Loop
    CentOS7 如何挂载网络设备
    mysql 全量备份以及增量备份
    zabbix 内网监控云服务器
  • 原文地址:https://www.cnblogs.com/Ken2018/p/15148127.html
Copyright © 2011-2022 走看看