Je souhaite faire une demande de post en transmettant des informations d'identification en utilisant isomorphic-fetch. Voici le code que j'ai pour l'instant:Authentique de base avec isomorphic-fetch
export default function fetchJson(url: string, options: any) {
options.headers = (<any>Object).assign({
'Accept': 'application/json',
'Content-Type': 'application/json'
}, options.headers);
return fetch(url, options)
.then(checkStatus)
.then(parseJSON);
}
export function fetchLogs(dispatch_ok: any, dispatch_error: any) {
var URL = "http://server_address:8080/api/getlogs/";
return fetchJson(URL, {
method: 'get',
credentials: 'include',
headers: {
Authorization: 'Basic '+window.btoa('user:passwd'),
}
}).then((data: any) => {
if (data.results.length != 0) {
dispatch_ok(data.results);
} else {
dispatch_error("No logs could be retrieved");
}
}).catch((error: any) => {
dispatch_error(error.message);
});
}
Ce code ne fonctionne pas car il redirige vers la page de connexion. Une idée sur la façon de faire ce travail?
Une idée sur comment je pourrais déboguer cela? – user3091275