Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Golang、cors和angularjs-头部缺失_Angularjs_Go_Cors - Fatal编程技术网

Golang、cors和angularjs-头部缺失

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

我在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 + 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不够熟悉,无法确定或建议解决方案。