【发布时间】:2023-03-29 12:53:02
【问题描述】:
我正在尝试进行 rabbitmq http api 调用以了解队列的情况以及其他信息...
我需要 3 个变量来传递给 api
1) url: (http://localhost:55672/api) 2) 用户名/密码: guest/guest 3) realm: "RabbitMQ Management" //我不确定这是否重要 4)路径:“/队列”
当我做出 curl 声明时,它会给出积极的回应
sudo curl -i -u guest:guest (http://localhost:55672)/api/queues
HTTP/1.1 200 OK
Server: MochiWeb/1.1 WebMachine/1.7 (participate in the frantic)
Date: Tue, 03 Jul 2012 01:39:05 GMT
Content-Type: application/json
Content-Length: 6176
Cache-Control: no-cache
但使用 groovy 的 httpbuilder。这是代码
def http = new HTTPBuilder("(http://localhost:55672/api)")
http.auth.basic 'guest','guest'
http.request(GET) { req ->
uri.path = '/queues'
response.success = { resp, reader ->
assert resp.statusLine.statusCode == 200
println "Got response: ${resp.statusLine}"
println "Content-Type: ${resp.headers.'Content-Type'}"
println reader.json
}
response.'404' = { println 'Not found' }
}
结果是“未找到”。我不包括领域,因为我无法在 httpbuilder 中插入“领域”。它只附带 OAuth 但是我需要对 rabbit mq http api 调用使用基本身份验证。
有谁知道如何在 httpbuilder groovy 中包含域名以进行基本身份验证?有没有其他方法。请告诉我!谢谢!
【问题讨论】:
标签: grails groovy rabbitmq httpbuilder