19
मैं fetch के साथ एक साधारण बुनियादी प्रमाणीकरण लिखना चाहता हूं, लेकिन मुझे 401 त्रुटि मिल रही है। यह गज़ब का अगर कोई मुझसे कहता है क्या कोड के साथ गलत क्या है जाएगा:लाने के साथ मूल प्रमाणीकरण?
let base64 = require('base-64');
let url = 'http://eu.httpbin.org/basic-auth/user/passwd';
let username = 'user';
let password = 'passwd';
let headers = new Headers();
//headers.append('Content-Type', 'text/json');
headers.append('Authorization', 'Basic' + base64.encode(username + ":" + password));
fetch(url, {method:'GET',
headers: headers,
//credentials: 'user:passwd'
})
.then(response => response.json())
.then(json => console.log(json));
//.done();
function parseJSON(response) {
return response.json()
}
क्या यह ठीक है अगर शीर्षलेख में 'मूल' शब्द के बाद कोई स्थान नहीं है? – Orifjon
ओह एफ ***, हाँ! धन्यवाद! पूरी तरह से याद किया ;-) –