admin管理员组文章数量:1303529
I am using flowroute api and need to fetch data but not sure how to add authentication credentials i.e can be seen when I pass the query url in the browser How can I pass it in the javascript. I am using wix platform and adding javascript code as given below
// For full API documentation, including code examples, visit
import {fetch} from 'wix-fetch';
$w.onReady(function () {
fetch(';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...
});
what is the correct method to pass username and password to the API so I can get a json response instead of current 401 Unauthorized response status
;limit=3
Updating my Answer to show you the Network Call Details Request & Response headers ae as given bwlow in the screenshot
I am using flowroute api and need to fetch data but not sure how to add authentication credentials i.e can be seen when I pass the query url in the browser How can I pass it in the javascript. I am using wix platform and adding javascript code as given below
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import {fetch} from 'wix-fetch';
$w.onReady(function () {
fetch('https://api.flowroute./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...
});
what is the correct method to pass username and password to the API so I can get a json response instead of current 401 Unauthorized response status
https://api.flowroute./v2/numbers/available?starts_with=800&limit=3
Updating my Answer to show you the Network Call Details Request & Response headers ae as given bwlow in the screenshot
Share Improve this question edited Feb 21, 2018 at 7:49 harshal asked Feb 20, 2018 at 4:05 harshalharshal 10.9k3 gold badges19 silver badges23 bronze badges1 Answer
Reset to default 6Try:
fetch('https://api.flowroute./v2/numbers/available?starts_with=800&limit=3?', {
method: 'get',
headers: {
"Content-Type": "text/plain",
'Authorization': 'Basic ' + btoa(username + ":" + password),
},
})
本文标签:
版权声明:本文标题:authentication - How to pass username and password credentials while fetching data from api in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741739411a2395214.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论