客户端浏览器用本机IP如(127.0.0.1)访问跳转成功,而用localhost访问40X问题:浏览器控制台报:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 403.
这是因为前后端分离项目,在前端项目的url指为本机ip如(127.0.0.1),而地址栏输入localhost而引发的跨域问题。
解决有二:
1,用你前端项目配置的ip地址直接访问,不要用localhost,避免出现跨域问题。
2,在本机的window/system32/drivers/etc/host 中配置ip与localhost相关联 (不推荐,因为本机ip是会变的)