I am trying to use Sonarqube webservice API. I need to pass some parameters along with username and password to this web service api.
For that purpose I have written this following code -
HttpClient client = new HttpClient();
String uri = "http://myUrl.sonar.com";
client.getState().setCredentials(new AuthScope(uri, 8080, AuthScope.ANY_REALM),
new UsernamePasswordCredentials("username", "password"));
GetMethod get = new GetMethod("http://myUrl.sonar.com/api/resources?"
+ "resource=110041&format=json&metrics=ncloc,coverage&verbose=true"
+ "&metrics=sqale_index,sqale_debt_ratio,ncloc,sqale_rating");
get.setDoAuthentication(true);
try {
int status = client.executeMethod(get);
System.out.println(status + "\n" + get.getResponseBodyAsString());
} catch (IOException e) {
e.printStackTrace();
} finally {
get.releaseConnection();
}
When I run this code from Eclipse, it returns
401
{"err_code":401,"err_msg":"Unauthorized"}
Any probable reason for this? the user name and passwords are correct.