简体   繁体   English

如何以JSON格式从Sonatype Nexus REST API获取结果

[英]How to get results from Sonatype Nexus REST API in JSON format

I'm using Sonatype Nexus REST core api to get repositories. 我正在使用Sonatype Nexus REST核心API来获取存储库。

The output format is XML. 输出格式是XML。 How can I get the output in JSON format? 如何以JSON格式获取输出?

I can see in the docs that the return type can be application/json . 我可以在文档中看到返回类型可以是application/json But I am completely in blank where to set this. 但我完全处于空白处。

As an example with curl here is a call to get the list of repositories 以curl为例,这是一个获取存储库列表的调用

curl http://localhost:8081/nexus/service/local/repositories

which will give you xml formatted output. 这将为您提供xml格式的输出。 To get the same in JSON format you just edit the HTTP header of the request like so 要以JSON格式获得相同的内容,您只需编辑请求的HTTP标头即可

curl -H "Accept: application/json" http://localhost:8081/nexus/service/local/repositories

Potentially you want to add credentials and specify the content type as well (especially if you are posting JSON load as part of the request). 您可能还想添加凭据并指定内容类型(特别是如果您在请求中发布JSON加载)。 You can also change to a POST.. 您也可以更改为POST ..

curl -X GET -u admin:admin123 -H "Accept: application/json" -H "Content-Type: application/json" http://localhost:8081/nexus/service/local/repositories

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM