我正在使用REST api中的服务,除“PUT”之外的所有类型的请求都有效。显然,使用PUT时,标头(数据)不会到达服务器,因此无法进行身份验证。如果我在URL中的查询字符串中发送数据,则服务器将按预期运行。 为什么数据没有到达那里?
// 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);
}
});
}
并且,这里是put请求(我基本上复制并粘贴了post,并更改了方法类型)..为什么这不会将数据发送到服务器?
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);
}
});
}
每当我使用“PUT”时,我得到401 ...因为数据没有到达。我检查了$ _GET和$ _POST,处理了put并且它们是空的。 如果我在查询字符串中发送数据,则put按预期工作...当我发送标题时,我只是不起作用。
如果有人能指出我正确的方向,我会很感激,所以我可以解决这个问题。