I am consuming a service from a REST api, and all types of request except "PUT" work. Apparently, when using PUT, the headers (data) are not arriving to the server, so authentication is no possible. If I send the data in a query string inside the url, the server behaves as expected. Why is the data not getting there?
// here is my ajax POST call.. it works as expected
function testPost(deviceId, segmentId) {
console.log('inside testPost function');
var url = "http://........../api/avoidsegments/" + deviceId;
$.ajax({
url: url,
type: "POST",
crossDomain: true,
dataType: "json",
data : {
"appID": ig_appID,
"clientCode": ig_clientCode,
"segmentID": segmentId,
},
success: function(output) {
console.log(output);
},
error: function(err) {
console.log('url: ', url);
console.log('error: ', err);
}
});
}
And, here is the put request (I basically copied and pasted post, and changed the method type).. Why does this not send the data to the server??
function testPut(deviceId, segmentId) {
console.log('inside testPut function');
var url = "http://........../api/avoidsegments/" + deviceId;
$.ajax({
url: url,
type: "POST",
crossDomain: true,
dataType: "json",
data : {
"appID": ig_appID,
"clientCode": ig_clientCode,
"segmentID": segmentId,
},
success: function(output) {
console.log(output);
},
error: function(err) {
console.log('url: ', url);
console.log('error: ', err);
}
});
}
Whenever I use "PUT", I get a 401... because the data is not arriving. I checked $_GET and $_POST where the put is handled and they are empty. If I send the data in a query string, put works as expected... I just doesn't work when I send headers.
I'd appreciate if anyone could point me towards the right direction so I can fix this problem.