微信oauth授权ajax跨域,微信公众号OAuth2用户授权报错跨域,Origin 'null' is therefore not allowed access...
重定向到微信授权页面时调试发现Status Code:301 Moved Permanently并且报错提示跨域:
XMLHttpRequest cannot load
https://open.weixin.qq.com/connect/oauth2/authorize...#wechat_redirect. Redirect
from 'https://open.weixin.qq.com/connect/oauth2/authorize...#wechat_redirect' to
'https://open.weixin.qq.com/connect/oauth2/authorize...#wechat_redirect' has been
blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the
requested resource. Origin 'null' is therefore not allowed access.
在调试界面发现Headers里面出现了两次重定向,所以才导致了这个问题。
解决方法是在微信提供的授权页面链接中添加connect_redirect=1:
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIR
ECT_URI&response_type=code&scope=SCOPE&state=STATE&connect_redirect=1#wechat_redirect
再请求时Status Code:200 OK
原文:https://www.cnblogs.com/huayueniansi/p/10456344.html
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)