0

I am trying to get an access token via RestTemplate.postForEntity().

myRestTemplate.postForEntity(authBaseUrl, request, Object.class);

I have a specific class for it, but let's use now a simple Object as type. It contains an access_token field. It works, because I can get response, but the length if the access tokens (which is a string) is 1196 character long. And I can get the same length in Postman too. But if I use the intelliJ built-in REST client, the length is 1199. Only the token from the intelliJ rest client works (So the longer).

Because I always get a new access token, it is impossible to get the same token twice. How can I debug it? What could be the problem?

1 Answers1

0

Is the code that generates the response available to you? if so in your response add a header content-length so you can see what the server sent and what you received. Also, debug the server side and see what is being generated. In addition take another 3d party Http client and test it with this client see if you see a difference. The Http clients that you can try are Apache Http client, OK Http client, or my favorite - a very simplistic client written by me as part of my own Open Source MgntUtils library. Here is the Javadoc for my http client Here is a link to a similar question where you can get the references for any of above mentioned Http clients: How to check the status of POST endpoint/url in java

Michael Gantman
  • 7,315
  • 2
  • 19
  • 36
  • No, it is a 3rd party API. So I can call it, but I don't have any code if it. – Jimmy Tudesky Sep 15 '22 at 14:42
  • 1
    OK, check if response has content-length header. It is a standard header and it should let you know how long response should be. Also try use 3-d party Http client to see if you see a difference – Michael Gantman Sep 15 '22 at 15:35
  • Always check the urls. :facepalm: I used the live server auth url, the credentials were valid here too. But when I tried to get access to the "stage data api", the access token was invalid. – Jimmy Tudesky Sep 15 '22 at 19:34
  • But I checked the okHttpClient, it is easy to use and works as expected. So thanks. I have a new tool in my pocket. :) – Jimmy Tudesky Sep 16 '22 at 06:33