How to use rest-api with Java HttpClient?


I want to write a script in Java for checking content in our confluence cloud automatically. First I tried it out with postman and that worked very well.

I then tried to write this in Java to add analyses to responses but my GET request is not working. I checked atlassian and java documentation but I don’t understand why it’s not working. Can someone give me a hint?

HttpClient httpClient = HttpClient.newBuilder()

HttpRequest request = HttpRequest.newBuilder()
    .setHeader("Authorization", "Basic username:api-token)
    .setHeader("Content-Type", "application/json")

HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

Thanks Marco

Okay, I changed to .version(HttpClient.Version.HTTP_1_1) and now it’s working.


Basic authorization seems doesn’t work any more