출처: https://bumcrush.tistory.com/182 [맑음때때로 여름]

상세 컨텐츠

본문 제목

content type

React

by 장동균 2020. 8. 28. 17:30

본문

https://blog.naver.com/writer0713/221853596497

 

[Spring] Post 요청과 Content-Type의 관계

​​실무에서 RestAPI를 만들면서 간혹 마주치는 이슈가 있었다.Client에서 POST 방식으로 요청을...

blog.naver.com

 

https://xn--xy1bk56a.run/axios/guide/

 

Axios | Axios 러닝 가이드

 

xn--xy1bk56a.run

axios 공식문서 번역

 

 

RestAPIestAPI에서는 보통 json type으로 data를 전송하고 받는다. 이를 위해서 content-type 을 application/json 으로 명시해야하는 것이다.

 

공부를 하다 궁금했던 것이 fetch를 사용하는 경우에는 content type을 application/json으로 명시하지만 axios를 사용하는 경우 content type을 명시하지 않는 영상들을 많이 봤다.

 

알아보니까 axios에서의 content type default 값이 application/json이라 명시하지 않는 것이었다. (fetch에도 default값이 있지만 application/json이 아니다. default 값이 어떤 거인지는 아까 검색해봤는데 까먹었다...)

 

하지만, 첫번째 블로그의 글 처럼 html form 태그를 사용하여 post 하거나 jQuery의 ajax 요청을 할 때 default content type은 application/x-www-form-urlencoded 가 된다. 따라서 이런 경우들과 fetch를 사용하는 경우 반드시 content type을 application/json으로 명시해야 한다.

'React' 카테고리의 다른 글

여러 개의 module 가져오기  (0) 2020.09.23
Maybe component(조건부 연산자)  (0) 2020.09.23
Link to, a href in React  (0) 2020.08.25
babel, webpack  (0) 2020.08.20
presentational component와 container component  (0) 2020.08.19

관련글 더보기

댓글 영역