zoukankan      html  css  js  c++  java
  • fetch跨域调用datasnap接收JSON对象方法

        fetchData() {
           (async ()=> {
      
            const valueObj = {
              UserName: 'jjw',
              Tel: '123456'
            }
    
            let d2 = await fetch('http://127.0.0.1:8080/datasnap/rest/TServerMethods1/"TestPost"', {
              method: 'POST',
              headers: {
                'Authorization': 'Basic ' + btoa('jjw'+':'+'jjw'),
              },
              body: JSON.stringify(valueObj),
            });
            console.log(await d2.json());
           })();
        }
    function TServerMethods1.TestPost(Value: TJSONObject): string;
    var
      User: TUser;
    begin
      Result := Value.ToString;
      try
        User := TBaseObject.JSONToObject<TUser>(Value);
        if User.UserName='jjw' then
          Result := 'ok'
        else
          Result := 'xxx';
        User.Free;
      except
        Result := 'asdfasdfasd';
      end;
    end;
    procedure TWebModule1.DSAuthenticationManager1UserAuthenticate(Sender: TObject;
      const Protocol, Context, User, Password: string; var valid: Boolean;
      UserRoles: TStrings);
    begin
      if (User='jjw') and (Password='jjw') then
        UserRoles.Add('admin')
      else
        valid := False;
    end;
  • 相关阅读:
    CF786E ALT
    CF704D Captain America
    [NOI2016]循环之美
    「PKUWC2018」猎人杀
    [HNOI2019]JOJO
    博客已转移
    $20200203$的数学作业
    20200202的数学作业
    NOIp 2016 选课 (DP)
    Luogu P2574 XOR的艺术 (线段树)
  • 原文地址:https://www.cnblogs.com/Jiaojiawang/p/13942203.html
Copyright © 2011-2022 走看看