Content-Type이란?
Http 통신에서 전송되는 데이터의 타입을 명시하기 위해 header에 실리는 정보다. 즉, api 요청 시 request에 실어 보내는 데이터(body)의 타입 정보다.
Content-Type 종류
1) Multipart Related MIME 타입
- Content-Type: Multipart/related <-- 기본형태
- Content-Type: Application/X-FixedRecord
2) XML Media의 타입
- Content-Type: text/xml
- Content-Type: Application/xml
- Content-Type: Application/xml-external-parsed-entity
- Content-Type: Application/xml-dtd
- Content-Type: Application/mathtml+xml
- Content-Type: Application/xslt+xml
3) Application의 타입
- Content-Type: Application/EDI-X12 <-- Defined in RFC 1767
- Content-Type: Application/EDIFACT <-- Defined in RFC 1767
- Content-Type: Application/javascript <-- Defined in RFC 4329
- Content-Type: Application/octet-stream : <-- 디폴트 미디어 타입은 운영체제 종종 실행파일, 다운로드를 의미
- Content-Type: Application/ogg <-- Defined in RFC 3534
- Content-Type: Application/x-shockwave-flash <-- Adobe Flash files
- Content-Type: Application/json <-- JavaScript Object Notation JSON; Defined in RFC 4627
- Content-Type: Application/x-www-form-urlencode <-- HTML Form 형태
4) 오디오 타입
- Content-Type: audio/mpeg <-- MP3 or other MPEG audio
- Content-Type: audio/x-ms-wma <-- Windows Media Audio;
- Content-Type: audio/vnd.rn-realaudio <-- RealAudio; 등등
5) Multipart 타입
- Content-Type: multipart/mixed: MIME E-mail;
- Content-Type: multipart/alternative: MIME E-mail;
- Content-Type: multipart/related: MIME E-mail <-- Defined in RFC 2387 and used by MHTML(HTML mail)
- Content-Type: multipart/formed-data <-- 파일 첨부
6) TEXT 타입
- Content-Type: text/css
- Content-Type: text/html
- Content-Type: text/javascript
- Content-Type: text/plain
- Content-Type: text/xml
Axios http 통신 예제
import axios from "axios";
async function example(bodyData) {
const params = new URLSearchParams();
params.append("bodyData", bodyData);
const config = {
headers: {
"Content-type": "application/x-www-form-urlencoded",
},
};
const { data } = await axios.post("api/url", params, config);
return data;
}
참조
https://jw910911.tistory.com/117
https://juyoung-1008.tistory.com/4