【问题标题】:How to get results from Sonatype Nexus REST API in JSON format如何以 JSON 格式从 Sonatype Nexus REST API 获取结果
【发布时间】:2014-12-09 12:23:20
【问题描述】:

我正在使用 Sonatype Nexus REST 核心 api 来获取存储库。

输出格式为 XML。如何获取 JSON 格式的输出?

我可以在文档中看到返回类型可以是application/json。但我完全不知道在哪里设置它。

【问题讨论】:

    标签: json api rest nexus


    【解决方案1】:

    以 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
    

    【讨论】:

    • 如何在 url 中授权 nexus 存储库?
    猜你喜欢
    • 2016-02-19
    • 2013-01-24
    • 1970-01-01
    • 2013-11-19
    • 1970-01-01
    • 2018-05-19
    • 2014-01-11
    • 2015-11-27
    • 2021-12-28
    相关资源
    最近更新 更多