如何在RabbitMQ中使用curl和HTTP API删除连接

如何在RabbitMQ中使用curl和HTTP API删除连接,curl,rabbitmq,Curl,Rabbitmq,RabbitMQ的HTTP API文档中给出了/API/connections/name可用于删除连接。但是curl-i-u guest:guest-X“DELETE”http://localhost:15672/api/connections/ --数据urlencode“${conn_name}”给出: HTTP/1.1 405 Method Not Allowed allow: HEAD, GET, OPTIONS content-length: 0 date: Wed, 12 Dec 2

RabbitMQ的HTTP API文档中给出了/API/connections/name可用于删除连接。但是
curl-i-u guest:guest-X“DELETE”http://localhost:15672/api/connections/ --数据urlencode“${conn_name}”
给出:

HTTP/1.1 405 Method Not Allowed
allow: HEAD, GET, OPTIONS
content-length: 0
date: Wed, 12 Dec 2018 16:54:48 GMT
server: Cowboy
vary: origin
然而,GET正在发挥作用<代码>curl-i-u guest:guest-X GEThttp://localhost:15672/api/connections/ --数据URL编码“${conn_name}”给出

HTTP/1.1 200 OK
cache-control: no-cache
content-length: 1175
content-type: application/json
date: Wed, 12 Dec 2018 16:48:32 GMT
server: Cowboy
vary: accept, accept-encoding, origin

[{"auth_mechanism":"PLAIN",...

请仔细阅读
/api/connections
DELETE
。您将注意到,此操作的正确URI是
/api/connections/name
,其中
name
是连接的名称。
curl
--data urlencode
选项主要用于
POST
请求(但请参见
-G
curl选项)。您的
GET
请求实际上返回了所有连接

因此,如果您的连接名为“My RabbitMQ connection”,则首先必须对其进行URL编码,并创建正确的URI:

curl -4vvvu guest:guest -X DELETE 'localhost:15672/api/connections/My%20RabbitMQ%20Connection'


注意:RabbitMQ团队监视并有时只回答有关StackOverflow的问题。

它没有使用--data urlencode“${conn_name}”参数除了保留字符外,还必须对自动生成的RMQ连接名称中显示的
字符(to
%3E
)进行URL编码。