Http Request, Response 란?
Http (HyperText Transfer Protocol)
Http Request, Http Response 는 Client, Server 가 데이터를 주고 받는 기본적인 통신 방식으로,
Client가 Server에 Request를 보내면, Server는 Client에 Response를 보내준다. 이 때 Request, Response 둘 다 특정한 포맷으로 해당되는 데이터를 갖고 있으며, 아스키로 인코딩된 텍스트 이다.
1. Http Request Format
1-1. 요청 라인 (Request Line)
Http Method URI Http version (ex. GET / HTTP/1.1)
1-2. 요청 헤더 (Request Header)
클라이언트와 요청에 대한 추가 정보를 담고 있으며, 각 Header는 Key: Value 형식
1-3. 빈 줄 (An Empty Line)
Header와 Body를 구분하기 위한 공백(CRLF)
1-4. 본문 (Optional Message Body)
요청 라인의 Method가 POST, PUT 에서 사용되며, 서버에 전송할 데이터
GET / HTTP/1.1
Host: www.a.com:8000
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate
Accept-Language: ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7
2. Http Response Format
2-1. 상태 라인 (Response Line)
the HTTP version, a status code, and description of the status 로 구성 (ex. HTTP/1.0 200 OK)
2-2. 응답 헤더 (Response Hedaer)
응답에 대한 추가 정보를 담고 있으며, Request와 마찬가지로 Key: Value 형식으로 관리
2-3. 빈 줄 (An Empty Line)
Header와 Body를 구분하기 위한 공백(CRLF)
2-4. 메세지 본문 (Message Body)
성공 시, 실제로 Client가 요청한 Data/ 실패 시, 에러 이유에 대한 Data
(If the client's request is successful, the requested data is sent. This data may be a copy of a file, or the response from a CGI program. If the client's request could not be fulfilled, the data may be a human-readable explanation of why the server couldn't fulfill the request.)
HTTP/1.0 200 OK
Date: Wed Apr 23 17:31:47 KST 2025
Server: JHTTP 2.0
Content-length: 1440
Content-type: text/html
이미지 및 참고 출처: https://www.oreilly.com/openbook/webclient/ch03.html