当我尝试将消息发布到Rabbitmq时,我得到了这个隐秘的“响应代码400(错误请求)”错误消息。这是我的要求:
got.post(`https://rabbit.somedomain.com/api/exchanges/%2F/${exchange}/publish`, {
headers: {
Authorization: 'Basic ' + Buffer.from('myusername:password').toString('base64'),
},
json: {
properties: {},
routing_key,
payload: 'test',
payload_encoding: 'string'
},
timeout: 10000,
responseType: 'json',
}).then(response => {
if (Number(response.statusCode) !== 200) {
throw new Error(response);
}
console.log('success');
}).catch(err => {
console.log('failed to publish message:', err);
});
如您所料,此请求可以使用Postman完美地工作。我得到成功的回应:
{
"routed": true
}
此外,该问题似乎是特定于/publish
端点的。例如,我没有从/bindings
或/exchanges
端点收到此错误。通常,错误响应的格式为{"error":"bad_request","reason":"whatever_is_wrong"}
,因此至少我可以进行调试,但此处不是这种情况。 This是最接近我发现的这个问题,但那里的建议并不能解决我的问题。顺便说一下,我正在nodejs服务器中执行此操作。在这里很困惑,我将不胜感激任何帮助。谢谢!