Invalid Token for QueryTask

Discussion created by asadim on Feb 8, 2012
Latest reply on Apr 4, 2012 by asadim

I have a secure Map Server that I can access by typing its url and token in the address bar of my browser: http://serverurl?token=token_value. However, when I call a QueryTask, I get an "Invalid Token" error:
{"code":498,"message":"Invalid token","details":[]}

Here's how I construct and run the QueryTask:
var url = "http://serverurl?token=token_value";
var task = new esri.tasks.QueryTask(url);
var q = new esri.tasks.Query();

// set query parameters ....

task.execute(q, callbackHandler);

Can someone point out to me the possible cause for this error?