서버로 넘어가지 않는 fetch 400 오류

코덩이·2022년 6월 15일
0

리액트

목록 보기
2/3
post-thumbnail

front 단에서 400오류가 발생하고 서버에서는 해당 라우터에 접근조차 되지 않는 경우

  • headers와 body를 다시 확인해보자.
  • body의 데이터 유형은 반드시 Content-Type 헤더와 일치해야 한다.
  • 아래의 경우 json 형태로 데이터를 보낸다고 headers에 명시해놨는데
    JSON.stringify() 메서드를 적용하지 않았을 때 400오류가 발생했다.
const thumbnailRes = await fetch(
      `http://localhost:5050/analysis/thumbnail`,
      {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        // JSON.stringify 안하면 400오류
        body: JSON.stringify({ url: analysis.videoPath 	}),
      }
);

JSON.stringify()

  • JSON.stringify() 메서드는 JavaScript 값이나 객체를 JSON 문자열로 변환한다.
profile
개발공부중

0개의 댓글