gpt4 book ai didi

angularjs - 使用 AngularJS 连接到 Splunk 的 REST API,如何解决 CORS 问题?

转载 作者:行者123 更新时间:2023-12-02 03:24:13 25 4
gpt4 key购买 nike

当我尝试从 AngularJS 发布数据时,出现以下错误。

XMLHttpRequest cannot load https://localhost:8089/services/auth/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

这是angularjs代码

var app = angular.module('myApp', []);
sessionkey='';
var req = {
method: 'POST',
url: 'https://localhost:8089/services/auth/login',
headers : {
'Content-Type':'application/x-www-form-urlencoded',
'Accept':'*/*'

},
data : {
username : 'admin',
password : 'admin',
output_mode : 'json'
}
};



app.controller('myController', function($scope, $http) {
$http(req).success(function($scope, $http){
sessionKey= retrieveSessionKey($scope, $http);

});

});

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

感谢任何输入!

最佳答案

来自 Splunk dev site :

Web apps that run outside of Splunk Web need to use a proxy server or cross-origin resource sharing (CORS) to communicate with the Splunk server due to Same Origin Policy (SOP) browser security policies.

If you are using CORS, you'll need to configure the Splunk server to allow your web site to communicate with it using a CORS connection. To do this, add your web site's address as a trusted HTTP origin to the crossOriginSharingPolicy attribute in the server.conf configuration file.

例如,将此节添加到 $SPLUNK_HOME/etc/system/local/server.conf 配置文件中,然后重新启动 Splunk:

[httpServer]
crossOriginSharingPolicy = your_site_address

关于angularjs - 使用 AngularJS 连接到 Splunk 的 REST API,如何解决 CORS 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31308952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com