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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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
AngularJS$http获取方法到后端服务器:请求方法:选项405_Angularjs_Clojure - Fatal编程技术网

AngularJS$http获取方法到后端服务器:请求方法:选项405

AngularJS$http获取方法到后端服务器:请求方法:选项405,angularjs,clojure,Angularjs,Clojure,$http GET请求到clojure后端,以获取服务列表。 我得到的是一个选项请求???,它得到了405个响应 <code> var config = {headers: { 'Authorization': 'Bearer d2VudHdvYW5nZV9tZQ', "X-Testing" : "testing" } }; $http.get(SERVER.MESSAGE_SERVICES, config) .success(funct

$http GET请求到clojure后端,以获取服务列表。 我得到的是一个选项请求???,它得到了405个响应

<code>
var config = {headers:  {
        'Authorization': 'Bearer d2VudHdvYW5nZV9tZQ',
        "X-Testing" : "testing"
    }
};
$http.get(SERVER.MESSAGE_SERVICES, config)
  .success(function(successCallback) {
    $scope.services = successCallback;
  })
  .error(function(errorCallback) {
    console.log(errorCallback.toString);
  }).
finally(function() {
  console.log("Message services rest call");
});
</code>

**clojure  backend**:
<code>
headers {"Access-Control-Allow-Origin" "*"
         "Access-Control-Allow-Headers" "X-Requested-With, Origin,Content-Type, Accept"
         "Access-Control-Allow-Methods" "GET, POST, OPTIONS"}
</code>

AngularJS发送选项请求没有问题,这是因为CORS标准强制这样做。请确保服务器配置为允许GET方法。

是,正如raso所建议的,此问题是由于跨源资源共享COR造成的。相同的旧隐私策略阻止JS/angularJS跨域提出请求

将服务器配置为允许跨域请求。 或
如果您使用的是Chrome,那么您可以使用它来解决这个问题。

在我的后端中,我添加了:访问控制允许方法GET、POST和选项这将允许获取服务。