关于一个跨域问题 如果想设置跨域才成功,除了设置AllowedMethods、AllowedOrigins以为,还要注意header问题
func (m *Cors) Cors() func(http.Handler) http.Handler {
return handlers.CORS(
handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "AccessToken", "X-CSRF-Token", "Authorization", "x-md-local-authorization", "x-md-local-userid"}),
handlers.AllowedMethods([]string{"GET", "POST", "PUT", "HEAD", "OPTIONS", "DELETE"}),
handlers.AllowedOrigins([]string{"*"}),
)
}
config.headers = {
'Content-Type': 'application/json',
'x-md-local-authorization': token,
'x-md-local-userid': user.id,
'x-md-local-useridss': user.id
}
如果前端请求方法里面多了一个自定义的头x-md-local-useridss,后台handlers.AllowedHeaders没有允许,也是不会放行的
|