0

我正在尝试进行rabbitmq http api调用以了解队列的存在方式和其他信息...

我需要 3 个变量才能传递给 api

1) url: (http://localhost:55672/api) 2) username/password: guest/guest 3) realm: "RabbitMQ Management" //我不确定这是否重要 4) path: "/queues"

当我做出 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 中包含域名以进行基本身份验证?有没有其他方法。请告诉我!谢谢!

4

1 回答 1

3

这行得通吗?

def http = new HTTPBuilder( 'http://localhost:55672' )
http.auth.basic 'guest','guest'
http.request(GET) { req ->
    uri.path = '/api/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' }
}

从您的基本网址中取出大括号和路径,添加/api到路径中

于 2012-07-03T11:30:47.387 回答