ionic3:错误2 --关于Content-Type和Access-****

1:

Error:
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:8100' is therefore not allowed access.


解决:

在后端设置 headers(因为现在是用自己写的后台做一个小的测试) Access-Control-Allow-Origin: *
(其实应该有很多别的解决方法, 但是我赶时间, 就先这样搞定测试一下,以后遇到了慢慢来~)
比如

express:

res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", 'Origin, X-Requested-With, Content-Type, Accept');
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
// res.header("Content-Type", "application/json;charset=utf-8");
res.header("Content-Type", "application/json;charset=utf-8");

2:

Error:
Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.


解决:

修改后端的Access-Control-Allow-Headers

比如我的:

res.header("Access-Control-Allow-Headers", 'Content-Type’)

=》

res.header("Access-Control-Allow-Headers", 'Origin, X-Requested-With, Content-Type, Accept');


至于为什么,我之后看看,现在只是记录一下哈!!!


附上 Web Docs网址,感兴趣有时间就好好进去看一看,肯定比我讲得好

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值