在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ 如何轉(zhuǎn)發(fā)請求解決跨域

如何轉(zhuǎn)發(fā)請求解決跨域

用vue和axios請求數(shù)據(jù)的時候出現(xiàn)了下面問題:
圖片描述

然后找到了以下解決方案:
圖片描述

但是我不知道這里的轉(zhuǎn)發(fā)請求和代理究竟是什么意思,不懂這里面的思路?是要用到nginx嗎?
哪位知道的麻煩講一下?

回答
編輯回答
念初

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>
2018年2月7日 12:04
編輯回答
近義詞

如果后臺是自己開發(fā)的,那么只需在后臺添加跨域支持就可以,不需要用到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;
    }
2017年11月14日 09:25
編輯回答
入她眼

這里的代理是指 自己的前端頁面,請求自己的后臺,自己的后臺用httpclient 去請求那個server。
如果那個server也是自己的,可以配置security設置允許跨域。

2018年3月23日 20:14