0

キューがどのように存在するか、およびその他の情報を知るために、rabbitmq http api 呼び出しを実行しようとしています...

APIに渡すには3つの変数が必要です

1) URL: (http://localhost:55672/api) 2) ユーザー名/パスワード: ゲスト/ゲスト 3) レルム: "RabbitMQ Management" //これが重要かどうかはわかりません 4) パス: "/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' }
}

ベースURLから中括弧とパスを取り出し、パスに追加/apiしました

于 2012-07-03T11:30:47.387 に答える