用vue和axios请求数据的时候出现了下面问题:
然后找到了以下解决方案:
但是我不知道这里的转发请求和代理究竟是什么意思,不懂这里面的思路?是要用到nginx吗?
哪位知道的麻烦讲一下?
用vue和axios请求数据的时候出现了下面问题:
然后找到了以下解决方案:
但是我不知道这里的转发请求和代理究竟是什么意思,不懂这里面的思路?是要用到nginx吗?
哪位知道的麻烦讲一下?
如果后台是自己开发的,那么只需在后台添加跨域支持就可以,不需要用到nginx
如果后台是SpringBoot
在继承了WebSecurityConfigurerAdapter的子类中添加跨域bean即可
@Bean
CorsConfigurationSource corsConfigurationSource()
{
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Collections.singletonList("*"));
configuration.setAllowedMethods(Collections.singletonList("*"));
configuration.setAllowedHeaders(Arrays.asList("Content-Type","Authorization"));
configuration.setMaxAge((long) 600000);
configuration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
springmvc 跨域
<!-- API 接口跨域配置 -->
<mvc:cors>
<mvc:mapping path="/**"
allowed-origins="*"
allowed-methods="POST, GET, OPTIONS, DELETE, PUT"
allowed-headers="Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
allow-credentials="true" />
</mvc:cors>
4 回答1.2k 阅读✓ 已解决
4 回答1.2k 阅读✓ 已解决
1 回答2.5k 阅读✓ 已解决
2 回答704 阅读✓ 已解决
2 回答1.7k 阅读
2 回答1.6k 阅读
2 回答1.3k 阅读
这里的代理是指 自己的前端页面,请求自己的后台,自己的后台用httpclient 去请求那个server。
如果那个server也是自己的,可以配置security设置允许跨域。