You are not logged in.
Pages: 1
I'm calling a REST service with mORMot like this:
function TForm9.Logon(const IPAddress: String; const Username, Password: String): Boolean;
var
t: variant;
json: RawUTF8;
url: String;
Values: TPUtf8CharDynArray;
jsondata: TDocVariantData;
begin
Result := False;
url := Format('https://%s/user/login', [IPAddress]);
TDocVariant.New(t);
t.username := Username;
t.password := Password;
json := TWinHTTP.Put(url, t, 'Content-Type: application/json', True);
jsondata := DocVariantData(_json(json).jsondata)^;
end;
This is the returned data:
{"serverinfo":{"authtype":"local","api_key":"b61c7ef7-2f44-41d3-bb3e-69681fe999b6","metricsip":"192.168.1.23","port":"8443","metricsport":"8081","ip":"192.168.1.23","version":"1.1.0.19"}}
DocVariantData fails with Exception class EDocVariant with message 'DocVariantType.Data(1<>TDocVariant)'.
function DocVariantData(const DocVariant: variant): PDocVariantData;
begin
with TVarData(DocVariant) do
if VType=DocVariantType.VarType then
result := @DocVariant else
if VType=varByRef or varVariant then
result := DocVariantData(PVariant(VPointer)^) else
raise EDocVariant.CreateUTF8('DocVariantType.Data(%<>TDocVariant)',[VType]);
end;
DocVariantData is null but why? Is there something invalid/unexpected in the returned JSON?
Offline
Silly mistake on my side, just started exploring and took this from example. Thanks for the clear explanation.
Offline
Pages: 1