Dev.끄적끈적

HTTP 메시지 이해하기 본문

Spring

HTTP 메시지 이해하기

YeouidoSexyDeveloper 2022. 3. 26. 00:46

[HTTP 메시지]

 

  • Client 와 Server 간 Request, Response 는 HTTP 메시지 규약을 따름
  • HTTP 메시지는 웹 서비스 개발자(백엔드, 프론트 개발자)에게 매우 중요한 내용!!
  • 스프링 MVC 이해를 위한 필수 내용만 학습

1) 메시지 구조

 

  1. 시작줄 (start line)
    1. Response 에선 '상태줄 (status line)' 이라고 부름
  2. 헤더 (headers)
  3. 본문 (body)

2) Request 메시지

  1. 시작줄: API 요청 내용
  2. GET **naver.com** HTTP/1.1
  3. 헤더
    • "Content type"
      1. 없음
      2. HTML <form> 태그로 요청 시
      3. Content type: application/x-www-form-urlencoded
      4. AJAX 요청
      5. Content type: application/json
  4. 본문
    1. GET 요청 시: (보통) 없음
    2. POST 요청 시: (보통) 사용자가 입력한 폼 데이터
    3. name=홍길동&age=20

3) Response 메시지

  1. 상태줄: API 요청 결과 (상태 코드, 상태 텍스트)
  2. HTTP/1.1 **404** **Not Found**
  3. 헤더
    • "Content type"
      1. 없음
      2. Response 본문 내용이 HTML 인 경우
      3. Content type: text/html
      4. Response 본문 내용이 JSON 인 경우
      5. Content type: application/json
    • "Location" 
    • Location: <http://localhost:8080/hello.html>
    • Redirect 할 페이지 URL
  4. 본문
    1. HTML
    2. <!DOCTYPE html> <html> <head><title>By @ResponseBody</title></head> <body>Hello, Spring 정적 웹 페이지!!</body> </html>
    3. JSON
    4. { "name":"홍길동", "age": 20 }

 

 

'Spring' 카테고리의 다른 글

Controller, Service, Repository 역할, 분리  (0) 2022.03.27
리팩토링이란?  (0) 2022.03.27
IntelliJ Annotation processing 설정  (0) 2022.03.24
Spring 입문 강의 Notion 링크  (0) 2022.03.23
Spring 입문 week1  (0) 2022.03.18