用js开发了一个单页应用,api使用了fecshop的appserver,使用登录提交接口出现跨域问题

问题咨询 · tgy3300 · 于 5年前 发布 · 1704 次阅读

错误提示如下:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://api.zl.com/customer/login/account. (Reason: expected ‘true’ in CORS header ‘Access-Control-Allow-Credentials’).

我的环境说明:

fecshop已经升级到了1.6.3.0
js应用域名:app.zl.com
appserver域名:api.zl.com

fecshop中appserver的相关配置如下:

--@appserver\config\fecshop_local_services\Store.php--

'stores' => [
	...
	'api.zl.com' => [...]
	...
]

--@appserver\config\fecshop_local_services\Helper.php--

'appserver_cors' => [
	...
	'Origin' => ['http://app.zl.com'],
	...
]

--@appserver\web\index.php--

/*
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
...
}
*/

该文件没有动过,该部分依旧是注释掉的

登录表单提交后,请求信息如下截图:

共收到 15 条回复
tgy3300#15年前 0 个赞

论坛搜索了相关跨域的帖子,也没找到解决办法

Fecmall#25年前 0 个赞

你用的是https?

tgy3300#35年前 0 个赞

不是,http

tgy3300#45年前 0 个赞

现在还是本地开发测试阶段,所以是http,上线后,肯定是https

tgy3300#65年前 0 个赞

更新了,问题还是存在,

/customer/login/account

该接口所在的文件是

@fecshop\app\appserver\modules\Customer\controllers\LoginController.php

该文件继承的是 @fecshop\app\appserver\modules\AppserverController.php 文件,上面更新的文件是@fecshop\app\appserver\modules\AppserverTokenController.php,有用吗?

Fecmall#85年前 0 个赞

@tgy3300 #6楼 你的这个问题,自己去看代码逻辑,读一下代码就明白了,没有必要问,本人也不会回复。

tgy3300#95年前 0 个赞

好的,上面的问题消失了,现在出现新的提示,

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://api.zl.com/customer/login/account. (Reason: missing token ‘content-type’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel).

我的测试环境是centos 7 下的火狐浏览器

tgy3300#115年前 0 个赞

好了,问题解决了,感谢大佬:+1:,

现在的请求信息变成这样了

Fecmall#125年前 0 个赞

OK

tgy3300#135年前 0 个赞

你刚刚问是不是https,我上线后切换成https,没什么问题吧,

Fecmall#145年前 0 个赞

@tgy3300 #13楼 有问题,继续发帖。

tgy3300#155年前 0 个赞

好的

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics