国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - springboot vue 跨域問題的解決

springboot vue 跨域問題的解決

2021-06-06 13:13Sky786905664 Java教程

這篇文章主要介紹了springboot vue 跨域問題的解決,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

1、spring boot跨域配置有兩種方法

在后端使用spring boot。spring boot跨域非常簡單,只需書寫以下代碼即可。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@configuration
public class customcorsconfiguration {
 private corsconfiguration buildconfig() {
  corsconfiguration corsconfiguration = new corsconfiguration();
  corsconfiguration.addallowedorigin("*");
  corsconfiguration.addallowedheader("*");
  corsconfiguration.addallowedmethod("*");
   corsconfiguration.setallowcredentials(true);
   return corsconfiguration;
 }
 
 @bean
 public corsfilter corsfilter() {
  urlbasedcorsconfigurationsource source = new urlbasedcorsconfigurationsource();
  source.registercorsconfiguration("/**", buildconfig());
  return new corsfilter(source);
 }
}

2.nginx跨域配置

spring boot應用用nginx反向代理。而前端跨域請求的需求不減。

nginx跨域也比較簡單,只需添加以下配置即可。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
location / {
 proxy_pass http://localhost:8080;
 if ($request_method = 'options') {
 add_header 'access-control-allow-origin' '*';
 add_header 'access-control-allow-methods' 'get, post, options';
 add_header 'access-control-allow-headers' 'dnt,x-customheader,keep-alive,user-agent,x-requested-with,if-modified-since,cache-control,content-type,content-range,range,token';
 add_header 'access-control-max-age' 1728000;
 add_header 'content-type' 'text/plain; charset=utf-8';
 add_header 'content-length' 0;
 return 204;
 }
 if ($request_method = 'post') {
 add_header 'access-control-allow-origin' '*';
 add_header 'access-control-allow-methods' 'get, post, options';
 add_header 'access-control-allow-headers' 'dnt,x-customheader,keep-alive,user-agent,x-requested-with,if-modified-since,cache-control,content-type,content-range,range,token';
 add_header 'access-control-expose-headers' 'dnt,x-customheader,keep-alive,user-agent,x-requested-with,if-modified-since,cache-control,content-type,content-range,range,token';
 }
 if ($request_method = 'get') {
 add_header 'access-control-allow-origin' '*';
 add_header 'access-control-allow-methods' 'get, post, options';
 add_header 'access-control-allow-headers' 'dnt,x-customheader,keep-alive,user-agent,x-requested-with,if-modified-since,cache-control,content-type,content-range,range,token';
 add_header 'access-control-expose-headers' 'dnt,x-customheader,keep-alive,user-agent,x-requested-with,if-modified-since,cache-control,content-type,content-range,range,token';
 }
}

其中:add_header 'access-control-expose-headers' 務必加上你請求時所帶的header。

例如本例中的“token”,其實是前端傳給后端過來的。如果記不得也沒有關系,瀏覽器的調試器會有詳細說明。

三、瀏覽器設置跨域

chrome、firefox本身是可以通過配置支持跨域請求的。

chrome跨域:參考文檔:chrome跨域

四、前端vue設置跨域

先設置 axios

?
1
2
3
4
5
6
axios.defaults.withcredentials = true;
axios.defaults.headers.common['x-requested-with'] = 'xmlhttprequest'; //證明是ajax 請求
psot 請求加入
headers: {
  'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
}

設置config 文件下面的index.js 然后就可以再其它頁面訪問了

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/sky786905664/article/details/79189378

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产一区亚洲二区三区 | 国产一区二区三区播放 | 丝袜+亚洲+另类+欧美+变态 | 中文字幕日韩欧美 | 久草新免费 | 羞羞视频免费观看 | 蜜桃成人在线观看 | 日韩一区二区三区在线视频 | 日韩欧美三级 | 国产成人精品一区二区三区视频 | 亚洲欧美日韩一区 | 成年人在线免费观看视频网站 | 激情久久久久 | 国产高清一区二区 | 国产大片在线观看 | 一级二级黄色大片 | 国产精品视频在线播放 | 国产精品久久久久久久福利院 | 欧美午夜精品久久久久久浪潮 | 狠狠干av| www.国产| 亚洲一一在线 | 中文字幕高清在线观看 | 中文字幕一区二区三区在线视频 | 亚洲免费在线视频 | 福利片一区二区 | 99精品一区二区 | 五月天激情综合网 | 韩日在线观看视频 | 在线观看国产 | 成人三区 | 久久高清精品 | 国产精品一二三在线观看 | 日本一区二区中文字幕 | 精品美女久久久 | 91看片| 亚洲国产aⅴ精品一区二区 少妇一级片免费看 | 国产精品视频入口 | 国产精品香蕉 | 在线播放一区二区三区 | 黄色在线免费 |