댓글 검색 목록

[javascript] Axios를 사용하여 인증 헤더를 보내는 방법

페이지 정보

작성자 운영자 작성일 20-01-23 16:14 조회 506 댓글 0

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




댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.