本文主要是介绍CORS error 302 Found,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
CORS error && 302 Found
场景
单点登录认证:访问A系统,在B系统登录认证
此处代码为A系统
controller
@ResponseBody@GetMapping("/idp/loginCheck")public void loginCheck(HttpServletRequest request, HttpServletResponse httpResponse) throws IOException {// bam 的服务器地址String amUrl = "https://www.baidu.com/";// 应用注册的唯一标识String clientId = "client_test";// 应用回调地址String redirectURI = request.getRequestURI();String requestUrl = amUrl + "?client_id=" + clientId+ "&redirect_uri=" + redirectURI + "&response_type=code&state=" + state;httpResponse.sendRedirect(requestUrl);}
前端vue
export function loginCheck() {return http.get('/idp/loginCheck')
}
import { loginCheck } from '@/api/idp/idp'
router.beforeEach(async(to, from, next) => {loginCheck().then(resp => {if ('ok' === resp.data.msg) {// 跳转首页或者原跳转前页面// this.$router.push({ path: '/' });console.log("11111")} else {console.log("88888888888888888")}})
})
报错
解决方案
前端中访问后台接口的方式修改为:
window.location.href = `/idp/loginCheck`;
疑问
前面也试了nginx添加跨域配置、拦截器添加配置,都不生效,奇怪
这篇关于CORS error 302 Found的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!