0

I want to create QualityGates with the Web API in java.

        String auth = username + ":" + password;
        String authEncoded = Base64.getEncoder().encodeToString(auth.getBytes());
        URL sonar = new URL("http://xxx.xxx.xxx.xx:9000/api/qualitygates/create");
        HttpURLConnection conn = (HttpURLConnection) sonar.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization", "Basic " + authEncoded);

I dont seem to find anything in the topic of POST to web API. In the Code i basically try to connect to the API with the Admin user authentication. The Problem is, it doesnt matter what i do i always get ResponseCode 400. I know that it needs a name as a Property to create the QualityGate but that also doesnt seem to work.

My Question: What do i need to do to use the POST method on web API's.

Best regards!

Fleischey
  • 13
  • 3

1 Answers1

1

This isn't really a SonarQube question. It's a question about how to use POST apis. The API is returning a 400 error because you're not sending any data in the POST, and a POST expects data.

Read the answer to the following thread for hints on how to send data in a POST: Java - sending HTTP parameters via POST method easily .

David M. Karr
  • 14,317
  • 20
  • 94
  • 199