【问题标题】:Return Request in Spring APISpring API 中的返回请求
【发布时间】:2020-05-23 22:06:44
【问题描述】:

我的程序调用外部 API。现在我想直接将此响应返回给用户而不做任何更改。但不是我应该看到标题和正文的响应,我只得到这个响应:

 {
    "redirect": false,
    "successful": true
}

我的代码如下所示:

    try (Response response = client.newCall(request).execute()) {

        return response;
    }

当我在调试模式下查看响应对象时,我得到了我想要的所有信息。为什么用户看不到? 提前致谢

【问题讨论】:

    标签: java spring request response okhttp


    【解决方案1】:

    try 块在离开其作用域时会自动关闭响应。通过读取该块内的响应或摆脱 try 块来缓解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 1970-01-01
      相关资源
      最近更新 更多