angularjs - Golang、cors 和 angularjs - 缺少 header

标签 angularjs go cors

我正在使用 rs/cors在我的 Go API 中允许我的 Angularjs 应用程序发出直接请求。我添加了以下代码来配置 CORS:

crs := cors.New(cors.Options{AllowCredentials: true})
n.Use(crs) //Negroni include

但是当我发出请求时,我在浏览器中收到了No 'Access-Control-Allow-Origin' header is present on the requested resource消息。

我的请求是这样的:

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);
    });

我怎样才能解决这个问题?

最佳答案

修复了!我注意到随请求一起发送了一些不同的 header ,我必须明确允许所有这些 header 。

AllowedHeaders: []string{"accept", "authorization", "content-type"}

我希望这对某人有帮助。

关于angularjs - Golang、cors 和 angularjs - 缺少 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30535867/

相关文章:

go - 如何使用golang进行.docx模板(表格内容)

javascript - 对 CORS 预检的响应具有 HTTP 状态代码 405

angularjs - 使用 Lambda (JAVA) 的 CORS AWS

json - 将结构转换为 JSON,其中一个字段是另一个结构

angularjs - 为什么我会在指令定义中收到错误 TS2345?

javascript - 在 ng-repeat 中生成随机数

javascript - 将数据从 PHP(mysql) 传递到 AngularJS 时没有数据

go - interface(struct) 和 interface(struct).function 到底是什么

asp.net-web-api - Web API 中的 OWIN CORS 问题

javascript - javascript + angularjs 中的开始和停止时间