Java HTTPClient未返回API的最新数据

发布于 2025-01-25 10:58:24 字数 1345 浏览 5 评论 0原文

我正在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文