Java HTTPClient未返回API的最新数据
我正在IDEA 2020.1中使用Java 11(当然!)
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());
响应:
{"size":0,"limit":25,"isLastPage":true,"values":[],"start":0}
java.net.http.httpheaders@f406e94c {{cache-control = [not-cache,no-transform],content-type = [应用程序/json; charset = utf-8],date = [gmt 2022 5月2日,格林尼治标准时间],set-cookie = [bigipserverbitbucket-pool-7990 = 606120128.13855.0000;路径=/; httponly; secure],transver-engoding = [块],vary = [accept-auserid,x-auserid,cookie,x-ausername,accept-ensoding],x-arequestid = [*2J2Q3KX527X64646464646575X15] ],x-content-type-options = [nosniff]}}
postman中的响应
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"id": 12,
"version": 0, ...
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, ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论