Lumen - 我在尝试 POST 请求 header 时遇到 CORS 错误,但没有 header 一切正常
Lumen - I'm getting CORS error when trying POST request with some header, but without header everything is ok
所以我的问题是:我在子域 api.domain.com 上有 Lumen 服务器
从 domain.com 向 api.domain.com 发送 ajax 请求后:
$.ajax({
url: 'https://api.domain.com/login',
type: 'post',
headers: {
'Authorization': 'someJWTTOKEN'
'Content-Type': 'application/json'
},
data: {},
dataType: 'json',
success: function(result) {
console.log('result');
console.log(result);
},
error: function(error) {
console.log(error);
}
});
现在我收到 CORS 错误:
但是当我从 ajax 请求中删除 Header 时,一切正常。
效果很好:
$.ajax({
url: 'https://api.domain.com/login',
type: 'post',
headers: {
},
data: {},
dataType: 'json',
success: function(result) {
console.log('result');
console.log(result);
},
error: function(error) {
console.log(error);
}
});
我在将我的 React 应用程序连接到我的 Lumen API 时遇到了这个问题,但使用这个 PHP Package 解决了这个问题。在 README 中,他们解释了如何使用 Lumen 配置包。 Legit 花了我 2 分钟。
所以我的问题是:我在子域 api.domain.com 上有 Lumen 服务器 从 domain.com 向 api.domain.com 发送 ajax 请求后:
$.ajax({
url: 'https://api.domain.com/login',
type: 'post',
headers: {
'Authorization': 'someJWTTOKEN'
'Content-Type': 'application/json'
},
data: {},
dataType: 'json',
success: function(result) {
console.log('result');
console.log(result);
},
error: function(error) {
console.log(error);
}
});
现在我收到 CORS 错误:
但是当我从 ajax 请求中删除 Header 时,一切正常。
效果很好:
$.ajax({
url: 'https://api.domain.com/login',
type: 'post',
headers: {
},
data: {},
dataType: 'json',
success: function(result) {
console.log('result');
console.log(result);
},
error: function(error) {
console.log(error);
}
});
我在将我的 React 应用程序连接到我的 Lumen API 时遇到了这个问题,但使用这个 PHP Package 解决了这个问题。在 README 中,他们解释了如何使用 Lumen 配置包。 Legit 花了我 2 分钟。