【发布时间】:2017-07-02 17:16:39
【问题描述】:
我正在尝试做一个 $http.post,但是这个响应给了我这个错误。
XMLHttpRequest 无法加载 http://XXXXXXXXX:2222/server/api/v1/controllers。预检响应包含无效的 HTTP 状态代码 403
我在互联网上读到的所有内容都说这是 CORS 的错误,我试图解决这个问题,但没有成功。
这是我的 $http.post 方法。
// Set the Content-Type
$http.defaults.headers.post["Content-Type"] = "application/json";
// Delete the Requested With Header
delete $http.defaults.headers.common['X-Requested-With'];
var config = {
method: 'POST',
headers: {'Content-Type': 'application/json; charset=utf-8'}
}
$http.post("http://XXXXXXXXX:2222/server/api/v1/controllers", objToSave , config)
.then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log(response)
}, function errorCallback(error) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log(error)
});
我正在使用 Angular v1.5.5。
希望你能帮助我,
问候!
【问题讨论】:
-
CORS 错误 => 检查您的 服务器 端的 CORS 配置
标签: javascript angularjs cors