I created a Geoprocessing Service that creates a new user on my portal. However, one of the parameters is the password the user would like to use. My server enforces https and so does my web application; however, when consuming the GP service via the ESRI Javascript API's execute or submitJob functions, the request is submitted via GET rather than POST.
My question: Is there a way to enforce POST using the API? If not, am I able to consume the GP service via an ajax POST request?
Best, Tyler
Solved! Go to Solution.
I figured it out. Here is my AngularJS implementation.
// dependancy injection: $q, $http, $httpParamSerializer
function portalSignup() {
var deferred = $q.defer();
var requestConfig = {
method: 'POST',
url: 'https://<path to server>/<server name>/rest/services/<path to service>/execute',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
transformRequest: $httpParamSerializer,
data: {
f: 'json',
Username: 'First.Name',
Password: 'ValidPassword',
FullName: 'First Last',
Email: 'first.last@subdomain.domain.com'
}
};
$http(requestConfig)
.success(function (response) {
console.log('Success: Portal Created User:', response);
deferred.resolve(response);
}).error(function (err) {
console.log('Error: Portal Failed to Create User', err);
deferred.reject(err);
});
return deferred.promise;
}
I figured it out. Here is my AngularJS implementation.
// dependancy injection: $q, $http, $httpParamSerializer
function portalSignup() {
var deferred = $q.defer();
var requestConfig = {
method: 'POST',
url: 'https://<path to server>/<server name>/rest/services/<path to service>/execute',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
transformRequest: $httpParamSerializer,
data: {
f: 'json',
Username: 'First.Name',
Password: 'ValidPassword',
FullName: 'First Last',
Email: 'first.last@subdomain.domain.com'
}
};
$http(requestConfig)
.success(function (response) {
console.log('Success: Portal Created User:', response);
deferred.resolve(response);
}).error(function (err) {
console.log('Error: Portal Failed to Create User', err);
deferred.reject(err);
});
return deferred.promise;
}