2017-02-28 49 views
0

我想從React.js中的API獲取JSON。我嘗試與axios,superagent和fetch,但它不起作用?無法通過包含憑據的網址構建請求

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

錯誤:

回答

0

「請求不能從包括憑據的URL構建」試試這個改變

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

謝謝伊霍爾我試過,但也有同樣的錯誤 –

1

我認爲錯誤是讓你知道的問題是它不接受國書以這種方式。

您需要創建一個X-Auth-Token標頭並將標記添加到該標識。然後通過整個事情

相關問題