【发布时间】:2021-01-26 21:17:31
【问题描述】:
我将下面的代码作为 api 端点。我希望在访问端点时将 json 字符串显示在浏览器上。
但是,当我访问端点时,会下载一个文件。名为 api.json 的文件包含 {"key": "myKey"}。我不知道它为什么会生成一个文件。我能得到一些帮助吗?
谢谢!
@GetMapping(path="/getFields2", produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getFieldssec(@Context HttpServletRequest httpServletRequest)
{
return ResponseEntity.ok("{\"key\": \"myKey\"}");
}
【问题讨论】:
-
服务器只发送 JSON。然后浏览器决定做什么并决定下载它
-
使用标题
Content-Disposition=inline