728x90
POST
HTTP 요청 방법은 method에, 전송할 데이터는 body에, 헤더 값은 headers에 정의한다.
//POST - 데이터 생성
fetch("https://jsonplaceholder.typicode.com/posts", {
method: "POST", //HTTP 요청 방법
body: JSON.stringify({
//전송할 데이터
title: "foo",
body: "bar",
userId: 1,
}),
headers: {
//헤더 값 정의
"content-type": "application/json; charset=UTF-8", //content-type 정의
},
})
.then((response) => response.json())
.then((json) => console.log(json));
참고자료
'자바스크립트' 카테고리의 다른 글
Javascript, cookie에서 csrftoken 값 가져오기 (0) | 2022.07.27 |
---|---|
frontend, pipe에러 해결 (0) | 2022.07.25 |
Javascript, fetch FormData (0) | 2022.07.21 |
Javascript, fetch PUT (0) | 2022.07.21 |
Javascript, fetch GET (0) | 2022.07.21 |