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๊ฐ ์ด๋ฅผ ์ฒ๋ฆฌํด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
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
},
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ฟผ๋ฆฌ ๋ฌธ์์ด์ ์ง์ ํ๋ ๋ฐ
params
๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.