Request cannot be constructed from a URL that includes credentials

穿精又带淫゛_ 提交于 2019-12-10 10:38:57

问题


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);
    });

Error: "Request cannot be constructed from a URL that includes credentials"


回答1:


I think the error is letting you know the problem is it doesnt accept credentials in that manner.

You need to create a X-Auth-Token header and add the token to that. then pass the whole thing




回答2:


Try this changes

let myInit = {
    'method': 'GET',
    credentials: 'include' // or 'same-origin'
}


来源:https://stackoverflow.com/questions/42518520/request-cannot-be-constructed-from-a-url-that-includes-credentials

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!