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

uxh89sit  于 2023-10-20  发布在  RabbitMQ
关注(0)|答案(1)|浏览(194)

RabbitMQ的HTTP API文档中给出了/API/connections/name可以用来删除连接。但是curl -i -u guest:guest -X "DELETE" http://localhost:15672/api/connections/ --data-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 GET http://localhost:15672/api/connections/ --data-urlencode "${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",...
fkaflof6

fkaflof61#

请仔细重新阅读/api/connectionsDELETEAPI documentation。您会注意到此操作的正确URI是/api/connections/name,其中name是您的连接的名称。curl--data-urlencode选项主要用于POST请求(但请参见-Gcurl选项)。您的GET请求实际上返回了所有连接。
所以,如果你的连接名是“My RabbitMQ Connection”,你首先需要对其进行URL编码,并创建正确的URI:

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

相关问题