我正在使用flowroute api并且需要获取数据但不确定如何添加身份验证凭据,即当我在浏览器中传递查询 url 时可以看到如何在 javascript 中传递它。我正在使用 wix 平台并添加 javascript 代码,如下所示
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import {fetch} from 'wix-fetch';
$w.onReady(function () {
fetch('https://api.flowroute.com/v2/numbers/available?starts_with=800&limit=3?',{method: 'get',auth:{user:'28288282', pass:'099299292991'}})
.then( (httpResponse) => {
console.log(httpResponse.ok);
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
} )
.then(json => console.log(json))
.catch(err => console.log(err));
//TODO: write your page related code here...
});
将用户名和密码传递给 API 的正确方法是什么,这样我就可以获得 json 响应而不是当前的401 Unauthorized 响应状态
https://api.flowroute.com/v2/numbers/available?starts_with=800&limit=3