I have a scenario in which I have to deal with a misconfigured server, which only understands a stringified JSON. What works with the server is:
var req = JSON.stringify({id: 0, method: 'getToken', params: ['something', 'password', 'some_more_randomness']});
$http({
url: 'http://something.com/API',
method: 'POST',
data: req,
responseType: 'json'
}).success(function (data) {
console.log('data', data);
}); // works
And I've tried to use $resources to take the hassle out of the picture, and I have something like:
var apiService = angular.module('apiService', ['ngResource']);
/**
* apiService Module
*
*/
apiService.factory('API', ['$resource', function ($resource) {
return $resource('http://somethng.com/API', {}, {
getToken: {
method: 'POST',
params: JSON.stringify({id: 0, method: 'getToken', params: ['something', 'password', 'some_more_randomness']})
}
});
}]);
Which doesn't work. The server cannot parse the parameters. I'm afraid I don't have access to the server to allow posting properly to it.
What I'd like to do, is to make the exact request from within the service. Other variations – enclosing JSON.stringify inside [] doesn't help either.
What can be done here?
JSON.stringify({data: {id: 0, method: 'getToken', params: ['something', 'password', 'some_more_randomness']}})
? – Maxim Shoustin Mar 13 at 15:54params: JSON.stringify({data: {id: 0, method: 'getToken', params: ['something', 'password', 'some_more_randomness']}})
doesn't work – Ashesh Mar 13 at 15:59