AJAX POST请求:403 Forbidden在Chrome和Firefox中返回但不是curl

时间:2017-08-03 22:13:23

标签: jquery ajax google-chrome firefox curl

我正在使用AJAX执行简单的POST请求。该请求需要基本身份验证。

$.ajax({
    type: "POST",
    url: "http://bjpeter.ehawaii.gov:8080/ai-gateway/service/BRIM.json",
    data: '{"lang":"en","timestamp":"2017-08-03T20:16:18.273Z","result":{"parameters":{"entity":"ALOHA"}}}',
    headers: {
        "Accept" : "application/json",
        "Content-Type" : "application/json",
        "Authorization" : "Basic " + btoa("john:heaven")
    },
    success: function(result) {
        $("#result").val(result);
    },
    error: function(xhr, status, error) {
        $("#result").val(status + ": " + error);
    }
});

bjpeter.ehawaii.gov:8080指向我的机器,从中进行AJAX调用。我应该在响应中获取JSON数据。

但是,在Chrome中,回复是403 Forbiddenenter image description here

Firefox也返回了403 Forbiddenenter image description here

但是当我使用curl时,按预期返回了JSON数据:

curl -v -u john:heaven -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"lang":"en","timestamp":"2017-08-03T20:16:18.273Z","result":{"parameters":{"entity":"ALOHA"}}}' http://bjpeter.ehawaii.gov:8080/ai-gateway/service/BRIM.json

enter image description here

为什么Chrome和Firefox会返回403 Forbidden而不是JSON数据?我注意到Chrome中的远程地址为127.0.0.1:8080,Firefox中为:: 1。

0 个答案:

没有答案