Axios를 사용하여 인증 헤더를 보내는 방법 알아보기
https://flaviocopes.com/axios-send-authorization-header/
WordPress API를 사용하여 작업 중이었고 웹 사이트에 POST 요청을 수행하려면 인증을 받아야 했습니다.
가장 쉬운 방법은 기본 인증을 사용하는 것이었습니다.
Axios를 사용하고 있었기 때문에 Authorization 헤더를 다음과 같이 POST 요청으로 설정했습니다.
const username = ''
const password = ''
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
const url = 'https://...'
axios.post(url, {
headers: {
'Authorization': `Basic ${token}`
}
})
등록된 댓글이 없습니다.