Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

由于某些原因 需要跨域传cookie 如页面地址是 foo.com 服务端接口地址是 bar.com
Nginx已经做了如下配置

add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Origin $http_origin;

前端(vue)也配置了withCredentials: true

<script>
  new Vue({
    el: '#app',
    data: {
      url: 'https://bar.com/...',
      message: ''
    },
    methods: {

    },
    created() {
      axios
        .get(this.url, {
          withCredentials: true
        })
        .then((result) => {
          this.message = JSON.stringify(result, null, 4)
          console.log(JSON.stringify(result, null, 4))
        })
    }
  })
</script>

接口能正常调用 但是请求头中根本就没有cookie这一项

是不是根本就不支持呢 ?还是说还需要哪些额外的配置呢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

withCredentials 只会传 bar.com 的 cookies,你是不是想传 foo.com 的 cookies ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...