maskofa

Bridging BIOS - Data Capture :: Get Token

Nov 2nd, 2021 (edited)
1,635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.73 KB | None | 0 0
  1. function  TfrmUtama.getToken: String;
  2. var
  3.   sss: String;
  4.   stm: TStringStream;
  5.   res: IHTTPREsponse;
  6.   jso: TJSONObject;
  7. begin
  8.   sss := '{"username":"' + USER_ + '", "password":"' + PASS_ + '"}';
  9.   stm := TStringStream.Create(sss);
  10.  
  11.   try
  12.     res := http.Post(BURL_ + 'auth', stm);
  13.   except
  14.     on E:Exception do
  15.     begin
  16.       stm.Free;
  17.       result := 'error';
  18.       exit;
  19.     end;
  20.   end;
  21.   stm.Free;
  22.  
  23.   sss := res.ContentAsString;
  24.  
  25.   try
  26.     jso := TJSONObject(TJSONObject.ParseJSONValue(sss));
  27.   except
  28.     result := 'error';
  29.     exit;
  30.   end;
  31.  
  32.   try
  33.     jso := TJSONObject(jso.Values['data']);
  34.     sss := jso.Values['token'].Value;
  35.   except
  36.     result := 'error';
  37.     exit;
  38.   end;
  39.  
  40.   result := sss;
  41. end;
Advertisement