【发布时间】:2018-01-28 15:10:20
【问题描述】:
当 GET 请求作为运行状况检查发送到 RabbitMQ API 时,我无法传递凭据以避免身份验证对话框。 如果我传递带有凭据的 url (例如http://user:pass@localhost:15672/api/aliveness-test/%2F)
它收到以下错误 -
rabbitCol.js:12 Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Request cannot be constructed from a URL that includes credentials: http://user:pass@localhost:15672/api/aliveness-test/%2F
at rabbitColChecking (rabbitCol.js:12)
at allReqInt (allReqInt.js:5)
at HTMLAnchorElement.onclick ((index):108)
如果我在 url 中没有凭据的情况下发送此请求,它实际上发送请求正常,但身份验证对话框会在 UI 中弹出,这很烦人,也不是很漂亮。
请求如下 -
var fetch = require('node-fetch');
async function rabbitColChecking() {
let index;
const hostsRB = ['http://user:pass@host1:15672/api/aliveness-test/%2F', 'http://user:pass@host2:15672/api/aliveness-test/%2F', 'http://user:pass@host3:15672/api/aliveness-test/%2F', 'http://user:pass@host4:15672/api/aliveness-test/%2F];
let lengthVal = hostsRB.length;
for(let hostIndxRB = 0; hostIndxRB < lengthVal; hostIndxRB++) {
index = hostIndxRB;
let url = hostsRB[hostIndxRB];
fetch(url, {method: 'GET', credentials:'same-origin', redirect: 'follow', agent: null, headers: {"Content-Type": "text/plain"}, timeout: 5000}
).then(function (hostindxRB, res) {
handleLedResponseRB(res, hostindxRB);
}.bind(null, hostIndxRB));
await sleep(500);
}
}
发送此请求的触发器是某个 HTML 文件中的“onclick”函数。
我实际上已经尝试了我在网上看到的所有解决方案,但没有解决这个用例。
【问题讨论】:
标签: javascript node.js rest api fetch