Cant POST JSON data to https REST API via Ext.Ajax while GET is possible
Hi,
Im trying to use Ext.Ajax to post some data as JSON to a Rest API server. Its a cross domain request but the server uses CORS. Im able to do GET and retrieve JSON data with no problems but when trying to do a POST it fails. In the following code I try to do a login
Code:
login = function (callerInstance, user, pass, onLogin) {
Ext.Ajax.setUseDefaultXhrHeader(false);
var url = SERVER + "login";
var data = {};
data.username = user;
data.password = pass;
Ext.Ajax.request({
url: url,
method: 'POST',
jsonData: data,
success: function(response, opts) {
console.log(TAG + 'responseText: ' + response.responseText);
onLogin.call(callerInstance, LOGGED_IN, response.responseText);
},
failure: function(response, opts) {
console.log(TAG + 'server-side failure with status code ' + response.status);
console.log(TAG + 'responseText: ' + response.responseText);
onLogin.call(callerInstance, NOT_LOGGED_IN, response.responseText);
}
});
};
The result of this is
Code:
HosRestApi: server-side failure with status code 0
And if I comment out the jsonData line, I get this error:
Code:
HosRestApi: server-side failure with status code 500
HosRestApi: responseText: {"errorText":"Internal Server Error: Object reference not set to an instance of an object."}
So the server is trying to process the request but failing as there is no login data.
So Im not sure why is the first error I mentioned happening or where is happening, or whats the problem.
The URL is https, does that makes any difference?
Please help me on this one!