简体   繁体   English

Spring RestTemplate 响应字符串比预期的短

[英]Spring RestTemplate Response string is shorter than expected

I am trying to get an access token via RestTemplate.postForEntity().我正在尝试通过 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.我有一个特定的 class ,但现在让我们使用一个简单的 Object 作为类型。 It contains an access_token field.它包含一个 access_token 字段。 It works, because I can get response, but the length if the access tokens (which is a string) is 1196 character long.它有效,因为我可以得到响应,但是如果访问令牌(它是一个字符串)的长度是 1196 个字符长。 And I can get the same length in Postman too.我也可以在 Postman 中获得相同的长度。 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).但是如果我使用 intelliJ 内置的 REST 客户端,长度为 1199。只有来自 intelliJ rest 客户端的令牌有效(所以更长)。

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?可能是什么问题呢?

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.如果是这样,请在您的回复中添加 header 内容长度,以便您查看服务器发送的内容和收到的内容。 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.另外取另一个 3d 方 Http 客户端,用这个客户端测试它,看看你是否看到了不同。 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. 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这是我的 http 客户端的 Javadoc这是指向类似问题的链接,您可以在其中获取上述任何 Http 客户端的参考: 如何检查 Z93F725A07423FE1C889F448FB3 中的 POST 端点/url 的状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM