无法从包含凭证的URL构造请求 [英] Request cannot be constructed from a URL that includes credentials

查看:75
本文介绍了无法从包含凭证的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆