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;