func AccessJsMiddleware() gin.HandlerFunc {

return func(context*gin.Context) {

w:=context.Writer

      w.Header().Set(“Access-Control-Allow-Origin”,”*”)//允许访问所有域

      w.Header().Set(“Access-Control-Allow-Methods”,”*”)

w.Header().Set(“Access-Control-Allow-Headers”,”Content-Type”)

w.Header().Set(“Access-Control-Allow-Credentials”,”true”)

//w.Header().s

      context.Next()

if context.Request.Method“OPTIONS” {

w.WriteHeader(http.StatusOK)

return

      }

}

}

文章来源于互联网,如有雷同请联系站长删除:go 遇到uni的 CROS报错,

发表评论