【发布时间】:2014-12-09 12:23:20
【问题描述】:
我正在使用 Sonatype Nexus REST 核心 api 来获取存储库。
输出格式为 XML。如何获取 JSON 格式的输出?
我可以在文档中看到返回类型可以是application/json。但我完全不知道在哪里设置它。
【问题讨论】:
我正在使用 Sonatype Nexus REST 核心 api 来获取存储库。
输出格式为 XML。如何获取 JSON 格式的输出?
我可以在文档中看到返回类型可以是application/json。但我完全不知道在哪里设置它。
【问题讨论】:
以 curl 为例,这里调用获取存储库列表
curl http://localhost:8081/nexus/service/local/repositories
这将为您提供 xml 格式的输出。要获得相同的 JSON 格式,您只需像这样编辑请求的 HTTP 标头
curl -H "Accept: application/json" http://localhost:8081/nexus/service/local/repositories
您可能还想添加凭据并指定内容类型(尤其是当您将 JSON 加载作为请求的一部分发布时)。您也可以更改为 POST..
curl -X GET -u admin:admin123 -H "Accept: application/json" -H "Content-Type: application/json" http://localhost:8081/nexus/service/local/repositories
【讨论】: