Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TfrmUtama.getToken: String;
- var
- sss: String;
- stm: TStringStream;
- res: IHTTPREsponse;
- jso: TJSONObject;
- begin
- sss := '{"username":"' + USER_ + '", "password":"' + PASS_ + '"}';
- stm := TStringStream.Create(sss);
- try
- res := http.Post(BURL_ + 'auth', stm);
- except
- on E:Exception do
- begin
- stm.Free;
- result := 'error';
- exit;
- end;
- end;
- stm.Free;
- sss := res.ContentAsString;
- try
- jso := TJSONObject(TJSONObject.ParseJSONValue(sss));
- except
- result := 'error';
- exit;
- end;
- try
- jso := TJSONObject(jso.Values['data']);
- sss := jso.Values['token'].Value;
- except
- result := 'error';
- exit;
- end;
- result := sss;
- end;
Advertisement