我被分配了一项集成API的任务。我可以从API获取信息,但弹出一个窗口,要求我提交用户名和密码。我有用户名和密码,但是我的想法是登录时不需要弹出窗口。

代码如下:
const getPlate = () => {
let licensePlate = document.getElementById('licensePlate');
let licensePlateNumber = licensePlate.value;
if (licensePlate.value === "") {
alert('¡Debe introducir el número de matrícula para poder avanzar!');
} else {
Axios.get( * URL GOES HERE * ).then((response) => {
let plate = response;
console.log(plate.data[i].make);
});
}
}
<div id="carDataContainer">
<div id="licensePlateContainer">
<input type="text" name="licensePlate" id="licensePlate" placeholder="Matrícula - ej. 001 BNDO"></input>
<button type="button" id="plateBtn" onClick={ getPlate }>Search</button>
</div>
</div>发布于 2021-07-21 23:37:30
您应该向axios提供用户/密码(看起来应该是基本身份验证)。尝试将该信息添加到您的请求中:
Axios.get( * URL GOES HERE *, {
auth: {
username: "your-username",
password: "your-pass",
}
} ).then((response) => {
let plate = response;
console.log(plate.data[i].make);
});
}发布于 2021-07-21 23:38:49
您需要基本身份验证
请参阅:https://stackoverflow.com/a/44239543/7662325
另外,如果这不起作用,您可以使用以下命令:https://stackoverflow.com/a/53939140/7662325
https://stackoverflow.com/questions/68472318
复制相似问题