I'm attempting to better understand the AGS token service and cannot seem to get thru some errors (probably something simple I'm missing). For starters, I simply just want to generate a token for a secured feature service and see it as a string/console. That's it.
Here's my sample that is hitting the error "Method not supported" in the console.log(error.message)….
var tokRequest = esriRequest({
url: "https://myAGS/tokens/generateToken",
method: "post",
content: {
f: "json",
username: "myUsername",
password: "myPassword",
referer: "<https://myAppPageURL>"
}
}).then(
function (response) {
console.log("Success: ", response.toJson);
}, function (error) {
console.log("Error: ", error.message); //<--error hits here
});
Any help is appreciated.
No, I don't have those "<" ">" in the url.
Is this correct:
url: "https://myAGS/tokens/generateToken"
or this:
url: "https://myAGS/tokens"
If I use the later I get a different error related to CORS.
James,
No the referer need to be the url of the app that your code is running in (i.e. https://localhost/myapp).
Even sending request via POSTMAN I get error:
{"error":{"code":405,"message":"Method not supported","details":"HTTP GET is disabled
Using Postman you have to use POST and not GET.
I think it's just user error. I had the set to POST but it keeps sending GET requests for some reason.
I was able to successfully request a token in POSTMAN but still unable to programmatically get it done with the same parameters specified.