npm install base-64
.d.ts 를 지원하므로 typescript로 작성한다면 @types/basic-64를 설치하면 됨.
import base64 from 'base-64';
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()
}
나의 경우 아래와 같이 작성함
let data = {
method: 'POST',
// body: JSON.stringify({
// })
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Basic ' + base64.encode('user:password')
}
}
fetch(`http://url`,data)
.then((response)=>response.json())
.then((json)=>{
console.log(json);
})
'프로그래밍 > React' 카테고리의 다른 글
React-Native apple 로그인 구현 with TypeScript (0) | 2020.08.18 |
---|---|
React-Native Base64 string을 이미지로 표현 (0) | 2020.08.13 |
[React-native] VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead. (0) | 2020.07.30 |
React-Native TypeScript ScrollView To The End (0) | 2020.07.16 |
React Router (0) | 2020.03.12 |