我们在移动端开发的时候,如果调用外部接口,容易出现跨域问题,问题如下:
英文描述:
The value of the ‘Access-Control-Allow-Origin’ header in the response
must not be the wildcard ‘*’ when the request’s credentials mode is
‘include’。
我们的解决方案:
1、服务器端设置:
Access-Control-Allow-Headers:Origin, Content-Type, cache-control,postman-token,Cookie, Accept
Access-Control-Allow-Origin:*,(如果是指定域名,可以设置https://www.google.com,https://www.baidu.com )
Access-Control-Allow-Credentials:true
2、前端程序设置
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'POST'
response.headers['Access-Control-Allow-Headers'] = 'Content-Type, X-Requested-With'
3、VUE前端程序设置
axios.defaults.withCredentials = true;