개발/Spring
HTTP 메시지 이해하기
GD_dev
2022. 3. 26. 00:46
[HTTP 메시지]
- Client 와 Server 간 Request, Response 는 HTTP 메시지 규약을 따름
- HTTP 메시지는 웹 서비스 개발자(백엔드, 프론트 개발자)에게 매우 중요한 내용!!
- 스프링 MVC 이해를 위한 필수 내용만 학습
1) 메시지 구조
- <aside> 🌐 참고: HTTP 메시지 설명 (MDN Web Docs)
- 시작줄 (start line)
- Response 에선 '상태줄 (status line)' 이라고 부름
- 헤더 (headers)
- 본문 (body)
2) Request 메시지
- 시작줄: API 요청 내용
- GET **naver.com** HTTP/1.1
- 헤더
- "Content type"
- 없음
- HTML <form> 태그로 요청 시
- Content type: application/x-www-form-urlencoded
- AJAX 요청
- Content type: application/json
- "Content type"
- 본문
- GET 요청 시: (보통) 없음
- POST 요청 시: (보통) 사용자가 입력한 폼 데이터
- name=홍길동&age=20
3) Response 메시지
- 상태줄: API 요청 결과 (상태 코드, 상태 텍스트)
- HTTP/1.1 **404** **Not Found**
- 헤더
- "Content type"
- 없음
- Response 본문 내용이 HTML 인 경우
- Content type: text/html
- Response 본문 내용이 JSON 인 경우
- Content type: application/json
- "Location"
Location: <http://localhost:8080/hello.html>
- Redirect 할 페이지 URL
- "Content type"
- 본문
- HTML
- <!DOCTYPE html> <html> <head><title>By @ResponseBody</title></head> <body>Hello, Spring 정적 웹 페이지!!</body> </html>
- JSON
- { "name":"홍길동", "age": 20 }