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;
    
    
  • 相关阅读:
    Leetcode 538. Convert BST to Greater Tree
    Leetcode 530. Minimum Absolute Difference in BST
    Leetcode 501. Find Mode in Binary Search Tree
    Leetcode 437. Path Sum III
    Leetcode 404. Sum of Left Leaves
    Leetcode 257. Binary Tree Paths
    Leetcode 235. Lowest Common Ancestor of a Binary Search Tree
    Leetcode 226. Invert Binary Tree
    Leetcode 112. Path Sum
    Leetcode 111. Minimum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/Ken2018/p/15148127.html
Copyright © 2011-2022 走看看