Axios: ์ฟผ๋ฆฌ์ŠคํŠธ๋ง ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

์— ๋งŒ๋“  2017๋…„ 03์›” 04์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: axios/axios

http://stackoverflow.com/questions/31756756/axios-http-client-how-to-construct-http-post- ๋ฅผ ์ฐพ์„ ๋•Œ๊นŒ์ง€ Axios๊ฐ€ ์ž˜๋ชป๋œ ํ˜•์‹์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋‚ด๋Š” ์ด์œ ๋ฅผ ์•Œ์•„๋‚ด๋ ค๊ณ  ๊ฑฐ์˜ ํ•˜๋ฃจ ์ข…์ผ ๋ณด๋ƒˆ์Šต๋‹ˆ๋‹ค.

axios.post(
  '/api/v1/auth/login',
  querystring.stringify({ // <-- this is what fixed it. JSON.stringify didn't help here
    user_id: this.state.user_id,
    password: this.state.password,
    _csrf: result.data.csrfToken
  }),
  {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
.then((res) => {
  if (res.data && res.data) {
    console.log('here')
  }
})
.catch((err) => {
  console.log(err);
});

๊ทธ๋Ÿฌ๋‚˜ Axios๊ฐ€ ์ด๋ฅผ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

์ฟผ๋ฆฌ ๋ฌธ์ž์—ด์„ ์ง€์ •ํ•˜๋Š” ๋ฐ params ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  // `params` are the URL parameters to be sent with the request
  // Must be a plain object or a URLSearchParams object
  params: {
    ID: 12345
  },

๋ชจ๋“  3 ๋Œ“๊ธ€

readme์— ์ด๋ฏธ ์ง€์นจ์ด ์žˆ์œผ๋ฏ€๋กœ ๋‹ต์„ ์ฐพ๋Š” ๊ฒƒ์€ ๋งค์šฐ ์‰ฌ์› ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

https://github.com/mzabriskie/axios#using -applicationx-www-form-urlencoded-format

Axios๊ฐ€ ์ด๋ฅผ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋Š” ์ œ๊ฐ€ ๋Œ€๋‹ตํ•  ๋ฌธ์ œ๊ฐ€ ์•„๋‹ˆ์ง€๋งŒ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ฃผ์š” ์ดˆ์ ์€ JSON์„ ๋ณด๋‚ด๋Š” ๊ฒƒ์ด๋ฏ€๋กœ ํ•ด๋‹น ์‚ฌ์šฉ ์‚ฌ๋ก€์— ์ตœ์ ํ™”๋ฉ๋‹ˆ๋‹ค.

์˜ค, ๊ทธ ๋งํฌ๋ฅผ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋‚˜๋Š” ๊ทธ๊ฒƒ์„ ์ „์— ๋ณด์ง€ ๋ชปํ–ˆ๋‹ค.

์ฟผ๋ฆฌ ๋ฌธ์ž์—ด์„ ์ง€์ •ํ•˜๋Š” ๋ฐ params ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  // `params` are the URL parameters to be sent with the request
  // Must be a plain object or a URLSearchParams object
  params: {
    ID: 12345
  },
์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰