3

When I try to post data from AngularJS, I am getting the below error.

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.

Here is the angularjs code

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

});

});

How can I get around the issue?

Appreciate any input!

Murali Mohan
  • 126
  • 7

2 Answers2

1

From 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.

For example, add this stanza to the $SPLUNK_HOME/etc/system/local/server.conf configuration file, then restart Splunk:

[httpServer]
crossOriginSharingPolicy = your_site_address
Community
  • 1
  • 1
Hayley Guillou
  • 3,953
  • 4
  • 24
  • 34
0

Just leaving a note for other people who still have CORS problems even after setting the server.conf:

I also set up server.conf, web.conf, and inputs.conf in the $SPLUNK_HOME/etc/system/local/*.conf, and added the following:

Under server.conf add the following lines

[httpServer] 
crossOriginSharingPolicy = *

Under web.conf add the following lines

[settings]
crossOriginSharingPolicy = *

Under inputs.conf add the following lines

[http]
crossOriginSharingPolicy = *

I found this info from the splunk answer page

After the set up, everything started to work.

Minjeong Choi
  • 377
  • 2
  • 8