dongmoxin7111 2015-11-09 21:01
浏览 50

Jquery ajax:数据以“POST”到达服务器,但没有以“PUT”到达

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog