I'm sending a 'POST' request containing a JSON object converted to JSON from my Knockout observable via ko.toJSON
method. I send it using Amplify.
This is my Amplify setting:
amplify.request.define('addContract', 'ajax', {
url: '/api/contractmanager/contracts/create',
dataType: 'json',
type: 'POST'
});
And this is the method in my dataservise
to add data:
addContract = function (callbacks, data) {
return amplify.request({
resourceId: 'addContract',
data: data,
success: callbacks.success,
error: callbacks.error
});
};
Here is how I actually send the request:
contracts.addData = function (contractModel, callbacks) {
var contractModelJson = ko.toJSON(contractModel);
return $.Deferred(function (def) {
dataservice.contract.addContract({
success: function (dto) {
if (!dto) {
logger.error('Error saving!');
if (callbacks && callbacks.error) { callbacks.error(); }
def.reject();
return;
}
},
error: function (response) {
logger.error('Error saving!');
if (callbacks && callbacks.error) { callbacks.error(); }
def.reject(response);
return;
}
}, contractModelJson);
}).promise();
};
For the back-end I am using a RESTful web service with Jersey.
The problem is that as soon as I send the request I get a "HTTP Status 415 - Unsupported Media Type" and my server GlassFish says: "The server refused this request because the request entity is in a format not supported by the requested resource for the requested method (Unsupported Media Type)."
Do I need to set anything particular for this to work? Am I missing something?