连接到Go轧棉机时,角度为8 CORS
我用Golang's和。这是我使用的: 梅因,加油 在控制台中,Gin返回状态代码204 我认为这是CORS的问题,所以我实施了金酒: 不幸的是,它仍然不起作用。如果我将POST方法添加到允许的方法中,也不会:连接到Go轧棉机时,角度为8 CORS,go,cors,jwt,go-gin,Go,Cors,Jwt,Go Gin,我用Golang's和。这是我使用的: 梅因,加油 在控制台中,Gin返回状态代码204 我认为这是CORS的问题,所以我实施了金酒: 不幸的是,它仍然不起作用。如果我将POST方法添加到允许的方法中,也不会: AllowMethods: []string{"PUT", "PATCH", "POST"} 我最后一次尝试是使用代理,如中所述: proxy.conf.json angular.json 我重新启动了ng serve,但仍然出现错误。我根据代理文件中的配置将auth.serv
AllowMethods: []string{"PUT", "PATCH", "POST"}
我最后一次尝试是使用代理,如中所述:
proxy.conf.json
angular.json
我重新启动了ng serve,但仍然出现错误。我根据代理文件中的配置将auth.service和main.go中的URL更改为/api/login
我在这里做错了什么?将alloweaders:[]字符串{Origin}更改为alloweaders:[]字符串{content type}
headers = new HttpHeaders({ "Content-Type": "application/json" });
login(username: string, password: string): Promise<any> {
const url: string = `${this.BASE_URL}` + "/login";
const request = this.http
.post(
url,
JSON.stringify({ username: username, password: password }),
{ headers: this.headers }
)
.toPromise();
return request;
}
Access to XMLHttpRequest at 'http://127.0.0.1:8000/api/login' from origin 'http://localhost:4200' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:8000"},
AllowMethods: []string{"PUT", "PATCH"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return origin == "https://github.com"
},
MaxAge: 12 * time.Hour,
}))
AllowMethods: []string{"PUT", "PATCH", "POST"}
{
"/api": {
"target": "http://localhost:8000",
"secure": false
}
}
"options": {
"browserTarget": "your-application-name:build",
"proxyConfig": "src/proxy.conf.json"
}