不能从包含凭据的 URL 构建请求 [英] Request cannot be constructed from a URL that includes credentials
本文介绍了不能从包含凭据的 URL 构建请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从 React.js 中的 API 获取 JSON.我尝试过使用 axios、superagent 和 fetch 但它不起作用?
I want to get a JSON from an API in React.js. I'm tried with axios, superagent and fetch but it's doesn't worked?
let token = '****';
let url = 'https://'+ token +'@api.navitia.io/v1/coverage/fr-idf/stop_areas/stop_area%3AOIF%3ASA%3A59491/departures?';
let myInit = {
'method': 'GET'
}
fetch(url, myInit).then((response)=>{
return response.json();
}).then((data)=> {
console.log('ok');
}).catch(function(err){
console.log('Erreur: ' + err);
});
错误:无法从包含凭据的 URL 构建请求"
Error: "Request cannot be constructed from a URL that includes credentials"
推荐答案
我认为错误是让您知道问题在于它不以这种方式接受凭据.
I think the error is letting you know the problem is it doesnt accept credentials in that manner.
您需要创建一个 X-Auth-Token 标头并将令牌添加到该标头中.然后通过整个事情
You need to create a X-Auth-Token header and add the token to that. then pass the whole thing
这篇关于不能从包含凭据的 URL 构建请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文