I know already the same question has been asked for the preflight issue and so many solutions are provided but i tried almost all of them but its not helping me.
I have a rest api written in java(Sprint) and calling it in my js. My service is getting called and its getting success. I my java code i have written the code for the redirection but direction is not happening and i am getting the below error in browser console:
XMLHttpRequest cannot load https://myserver1:8281/myurl/ext. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'https://myserver2:21242, *', but only one is allowed.
I tried adding 'Access-Control-Allow-Origin':'*' in the header but still facing the issue. Also tried adding the OPTIONS in the allowed methods in the header.
Below is my js code:
$scope.validateToken = function(){
var config = {
headers : {
'ContentType': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'Expires': '-1',
'X-Requested-By': 'test'
},xhrFields: {
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Headers' : 'Origin, X-Requested-With, Content-Type, Accept',
'Access-Control-Allow-Methods' : 'GET,PUT,POST,OPTIONS'
}
};
$http.get($scope.getUrl, {headers:{'token': $scope.ssoLinkData.token}}).success(function(data, status, headers, config){
}).error(function (data, status, header, config) {
$scope.ResponseDetails = "Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + header +
"<hr />config: " + config;
});
Below is my java code:
@GET
@Path("/ext")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response myMethod() {
return Response.seeOther(getLocation(redirectionUrl)).
header("Access-Control-Allow-Origin", "*").
header("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE, OPTIONS").
header("Access-Control-Allow-Headers", "Origin, Content-Type, X-Auth-Token").
status(200).build();
}
I added the header information in my java code after seeing some post related to the issue. But that is also not helping me.
Can some please help me on this? Thanks in advance