发送POST请求奇怪的问题

时间:2018-08-08 08:02:39

标签: angularjs

我对ANGULAR和Web开发一般还是很陌生,目前正在开发Web工具。现在,我希望该工具将POST请求发送到Web服务,但是我遇到了一个奇怪的错误。现在,我的javascript中包含以下代码:

var data_info = { test_id: 'TEST', model_id: 'TEST:TEST_ID' };
//data_info = JSON.stringify(data_info);

var request_json = {
    method: 'POST',
    url: url,
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    },
    data: data_info,
    cache: false,
};

console.log(request_json);
$http(request_json).then(function successCallback(response) {
    // response code here
}

现在,此代码当前未通过预检请求检查,并且始终返回405。但是,如果我将请求JSON中的行 data:data_info 更改为新密钥,我们说正文:data_info ,它现在成功发送了请求,我可以确认该服务正在接收它。我不确定这里是什么问题,无法解决。

1 个答案:

答案 0 :(得分:0)

将标题更改为:

headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}

请尝试

相关问题