HI all. Need some help

HI all. Need some help
this code works OK in windows. but not on OSX (unauthorised error)
procedure TForm131.Button1Click(Sender: TObject);
var
i:integer;
tempstr,tempstr2,tempstr3,accesstoken:string;
lData: TStringStream;
aHeader: TURIParameters;
Return: IHTTPResponse;


begin
accesstoken:='c.3Z8l4Nh6AbWS71W5PW7sw711M5FlTuHLZSr2h41yZfw5HPy17jAiWAKXI5e68q7I5IGrlaHrrSm1hzw9I3DuQ4S9vmprwozVJUq3vauPWxrcHabfN1c5bADXnTIRVhLfqpVvLMlItfaRLgEM';

try
lData := TStringStream.Create();

NetHTTPClient1.ContentType:='application/json';
NetHTTPClient1.CustomHeaders['Authorization'] := 'Bearer '+accesstoken;

try
Return :=NetHTTPClient1.get('https://developer-api.nest.com', lData);
showmessage(Return.ContentAsString());
except on E: exception do

memo1.lines.add(e.message);
end;
finally

lData.SaveToFile('c:\nestthermostat.txt');
lData.disposeof;


end;



end;

Maybe I should be using the REST components instead? (not sure how though..tips?)

Comments

  1. weird...it worked once..but not again...help!,lol

    ReplyDelete
  2. seems to just randomly work on OSX (but works every time on windows). might be a cache issue?..a bit frustrating

    ReplyDelete
  3. succes. I discovered it was working only once after running the windows version first...anyway, got it working by using good old indy (with handle redirects set true) : try
    resp := TMemoryStream.Create;
    IdHTTP1.Response.ContentType:='application/json';
    IdHttp1.Request.CustomHeaders.AddValue('Authorization', 'Bearer '+accesstoken);
    try


    IdHTTP1.get('https://developer-api.nest.com', resp);
    resp.Position := 0; // <-- add this!!
    memo1.Lines.LoadFromStream(resp);
    except on E: exception do

    memo1.lines.add(e.message);
    end;
    finally

    resp.free;
    end;

    ReplyDelete

Post a Comment