Golang、cors和angularjs-头部缺失
我在Go API中使用了Angularjs应用程序来直接请求。我添加了以下代码来配置CORS:Golang、cors和angularjs-头部缺失,angularjs,go,cors,Angularjs,Go,Cors,我在Go API中使用了Angularjs应用程序来直接请求。我添加了以下代码来配置CORS: crs := cors.New(cors.Options{AllowCredentials: true}) n.Use(crs) //Negroni include 但是,当我发出请求时,浏览器中请求的资源上没有“Access Control Allow Origin”标题 我的请求如下所示: var req = { method: 'POST', url: endPoint + v
crs := cors.New(cors.Options{AllowCredentials: true})
n.Use(crs) //Negroni include
但是,当我发出请求时,浏览器中请求的资源上没有“Access Control Allow Origin”标题
我的请求如下所示:
var req = {
method: 'POST',
url: endPoint + version + method,
headers: {
'Authorization': 'Basic ' + btoa(':' + appId)
},
data: params
}
$http(req).
success(function(data, status, headers, config) {
callback(null, data);
}).
error(function(data, status, headers, config) {
callback(data);
});
我怎样才能绕过这个问题?解决了它!我注意到请求中发送了几个不同的头,我必须明确地允许所有这些头
AllowedHeaders: []string{"accept", "authorization", "content-type"}
我希望这对某人有所帮助。我猜您的Web服务器没有响应选项请求,但我对golang不够熟悉,无法确定或建议解决方案。