I have created an Android app using Meteor that only has a client side (no Meteor server side). The app uses the ArcGIS REST API to obtain a token and then posts user location data to a service. The app functions as expected in development (run from meteor on Android device) but not in production (install signed APK on Android device). The POST requests do not work in production.
I have tried a few different ways to implement the POST request, all of which work in development but not in production:
After a few straight days of trying to determine if the exact problem is in the code, a Meteor, CORS, or something else, I feel I have exhausted all avenues. I am not a CORS guru and I am not a server manager, etc so I am not completely sure how to troubleshoot. From the results listed above, it sounds like the requests are not being sent.
Below is some sanitized code for the three different POST functions I have tried. "getToken_ajax" is my original and preferred function. I assume since the app works in development it should work in production but likely with some modification in the code or updates to settings/parameters on the server. However, I am unsure of what needs to change. Any thoughts?
Thanks,
Josh
var getToken_ajax = function() { var tokenData = { username: "theusername", password: "thepassword", f: 'json', expiration: 60, client: 'referer', referer: window.location.origin }; $.ajax({ url: "https://<address>/arcgis/tokens/generateToken", dataType: 'json', type: 'POST', data: tokenData, crossDomain: true, success: function(data, textStatus, jqXHR) { $(".status").empty(); $("#status").empty().append("status: " + textStatus); $("#data").empty().append("data: " + JSON.stringify(data)); $("#jqXHR").empty().append("jqXHR: " + JSON.stringify(jqXHR)); }, error: function(data, textStatus, jqXHR) { $(".status").empty(); $("#status").empty().append("status: " + textStatus); $("#data").empty().append("data: " + JSON.stringify(data)); $("#jqXHR").empty().append("jqXHR: " + JSON.stringify(jqXHR)); } }); }; var getToken_meteorhttp = function() { var tokenData = { headers: { "Content-type": "application/x-www-form-urlencoded" }, params: { username: "theusername", password: "thepassword", f: 'json', expiration: 60, client: 'referer', referer: window.location.origin } }; Meteor.http.call("POST", "https://<address>/arcgis/tokens/generateToken", tokenData, function(error, response) { $(".status").empty(); $("#status").empty().append("status: " + JSON.stringify(error)); $("#response").empty().append("response: " + JSON.stringify(response)); }); }; var getToken_leaflet = function() { function serverAuth(callback) { L.esri.post('https://<address>/arcgis/tokens/generateToken', { username: "theusername", password: "thepassword", f: 'json', expiration: 86400, client: 'referer', referer: window.location.origin }, callback); }; serverAuth(function(error, response) { $(".status").empty(); $("#status").empty().append("status: " + JSON.stringify(error)); $("#response").empty().append("response: " + JSON.stringify(response)); }); };
Solved! Go to Solution.
Turns out there was not a proper certificate in place. Once fixed, everything worked as expected.
Turns out there was not a proper certificate in place. Once fixed, everything worked as expected.