【发布时间】:2017-02-11 15:45:16
【问题描述】:
我正在从浏览器向我的 EC2 AWS 服务器发出 POST 请求,但返回以下错误。
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.example.com' is therefore not allowed access. The response had HTTP status code 401.
我已经做了一些研究并发布了我需要在我的 EC2 AWS 服务器上启用 CORS - 我知道我应该添加一些类似的东西
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>http://www.example1.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>http://www.example2.com</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
</CORSRule>
</CORSConfiguration>
来自 AWS 文档:AWS EC2 CORS
但是我也不确定我实际上需要在哪里添加它。我的 AWS 服务器知识有限。
这是一个 Neo4j 数据库,调用是:
getRequest = function () {
$.ajax({
url: 'http://exampleEC2:port/',
type: 'POST',
dataType: 'JSON',
contentType: 'application/json;charset=UTF-8',
password: 'xxxxxx',
username: 'xxxx',
data: dataObject,
success: function (data) {
console.log("success");
},
error: function(error) {
console.log(error);
}
});
};
【问题讨论】:
标签: amazon-web-services amazon-ec2 cors request-headers response-headers