HTTP 405 Result on CORS OPTIONS Request

web_api

(Eric Stoces) #1

Hi-

I am trying to get project status for a given project key with basic authorization. I am able to get results from the query in Postman. When I try to get result in an ajax call with CORS, the request fails with the following error:

HTTP405: BAD METHOD - The HTTP verb used is not supported.
(XHR)OPTIONS - http://sonarqube.xxx.com/api/qualitygates/project_status?projectKey=DotNetCoreTemplate:Develop

In Web.Config we have the Access-Control_Allow-Origin set appropriately, Access-Control-Allow-Methods for GET and OPTIONS, Access-Control-Allow-Headers for Authorizaton, Origin, Content-Type (and others).

And the following ajax call:

$.ajax({
type: ‘GET’,
url: ‘http://sonarqube.xxx.com/api/qualitygates/project_status?projectKey=DotNetCoreTemplate:Develop’,
headers: {
“Authorization”: “Basic " + btoa(uName+”:"+passwrd)
},
success : function(data) {
console.log(data);
},
error: function (xhr,textStatus,errorThrown){
console.log(xhr.responseText);
console.log(textStatus);
console.log(errorThrown);
},
});

I am able to successfully call the API if it does not require Basic Authorization.