1

I'm running this code in Idea 2020.1 with Java 11 (of course!)

 String gitApiPrUrl = "https://bitbucket.myserver.com/rest/api/1.0/projects/PRJ/repos/my-repo/pull-requests";

        HttpRequest request = HttpRequest.newBuilder()
                .uri(new URI(gitApiPrUrl))
                .headers("Cache-Control", "no-store")
                .GET()
                .build();

        HttpResponse<String> response = HttpClient.newBuilder()
                .authenticator(authenticator())
                .build()
                .send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println(response.body());

Response:

{"size":0,"limit":25,"isLastPage":true,"values":[],"start":0}

java.net.http.HttpHeaders@f406e94c { {cache-control=[no-cache, no-transform], content-type=[application/json;charset=UTF-8], date=[Mon, 02 May 2022 08:47:34 GMT], set-cookie=[BIGipServerBITBUCKET-POOL-7990=606120128.13855.0000; path=/; Httponly; Secure], transfer-encoding=[chunked], vary=[accept-encoding,x-auserid,cookie,x-ausername,accept-encoding], x-arequestid=[*2J2Q3Kx527x646575x15], x-asen=[SEN-8378849], x-content-type-options=[nosniff]} }

Response in Postman

{
    "size": 1,
    "limit": 25,
    "isLastPage": true,
    "values": [
        {
            "id": 12,
            "version": 0, ...
Sree
  • 746
  • 6
  • 21
  • 3
    Is the authentication that you use with Http client exactly the same than the one you use in Postman? Have you tried [cleaning Postman's cache](https://stackoverflow.com/questions/28305273/how-to-delete-session-cookie-in-postman) and running the request again to check if you're not retrieving something that is cached? – Matteo NNZ May 02 '22 at 08:57
  • 1
    I found out the issue - the authenticator in HttpClient is not having any effect on the call. So it was a call without authorization in header. After adding http header for Authorization it's working. But funny thing is Bitbucket API is not complaining about this and returning some invalidate data instead :) hence the confusion. – Sree May 02 '22 at 09:17
  • Great. I suggest you write this as an answer and accept it yourself. it may help someone else who in the future will look for the same keywords – Matteo NNZ May 02 '22 at 10:23

0 Answers0