본문 바로가기
IT(Tip)

HTTP(HyperText Transfer Protocol) 구조 간단 정리

by good4me 2020. 8. 27.

goodthings4me.tistory.com

 

Start Line | Header | [CRLF] Body

■ 요청 메시지 구조

Start Line : HTTP메서드 /요청URL /HTTP버전
Header : Host, User-Agent, Accept, Connection, Content-Type, etc.
Body : 본문 내용(데이터)
예) 
GET /test/hellohtml HTTP/1.1
Accept: application/json
Accept-Encoding: 
Connection:
Content-Type: 
Host: 
User-Agent:

 

 응답 메시지 구조

Start Line : HTTP버전 /상태 코드 /상태 텍스트
Header : 요청 메시지 헤더와 유사
Body : 본문 내용(데이터)
예) 
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: text/html; charset=utf8
Date:
Server:

 

■ HTTP 응답 상태코드(100단위 구분)

1xx : Informational (정보 제공)
2xx : Success (성공)
3xx : Redirection (리다이렉션)
4xx : Client Error (클라이언트 에러)
5xx : Server Error (서버 에러)

 

■ 주요 HTTP 응답 상태코드

상태 코드 상태 텍스트 비고
200 Success 요청을 서버에서 정상적으로 처리함
201 Created 요청 처리되어 새로운 리소스 생성됨
202 Accepted 요청 접수 완료, 처리는 완료되지 않음
301 Moved Permanently 지정 리소스가 새 URL로 이동됨
303 See Other 다른 위치로 요청
307 Temporary Redirect 임시 리다이렉션 요청 필요
400 Bad Request 잘못된 요청 구문
401 Unauthorized 지정 리소스 액세스 권한 없음
402 Forbidden 지정 리소스 액세스 금지
404 Not Found 지정 리소스 못찾음
500 Intenal Server Error 서버 에러 발생
503 Service Unavailable 서버의 서비스 제공 불가

good4me.co.kr

 

■ HTTPStatus

from http import HTTPStatus
for http in HTTPStatus:
    print(http.value, http)


[실행 결과]

100 HTTPStatus.CONTINUE
101 HTTPStatus.SWITCHING_PROTOCOLS
102 HTTPStatus.PROCESSING
200 HTTPStatus.OK
201 HTTPStatus.CREATED
202 HTTPStatus.ACCEPTED
203 HTTPStatus.NON_AUTHORITATIVE_INFORMATION
204 HTTPStatus.NO_CONTENT
205 HTTPStatus.RESET_CONTENT
206 HTTPStatus.PARTIAL_CONTENT
207 HTTPStatus.MULTI_STATUS
208 HTTPStatus.ALREADY_REPORTED
226 HTTPStatus.IM_USED
300 HTTPStatus.MULTIPLE_CHOICES
301 HTTPStatus.MOVED_PERMANENTLY
302 HTTPStatus.FOUND
303 HTTPStatus.SEE_OTHER
304 HTTPStatus.NOT_MODIFIED
305 HTTPStatus.USE_PROXY
307 HTTPStatus.TEMPORARY_REDIRECT
308 HTTPStatus.PERMANENT_REDIRECT
400 HTTPStatus.BAD_REQUEST
401 HTTPStatus.UNAUTHORIZED
402 HTTPStatus.PAYMENT_REQUIRED
403 HTTPStatus.FORBIDDEN
404 HTTPStatus.NOT_FOUND
405 HTTPStatus.METHOD_NOT_ALLOWED
406 HTTPStatus.NOT_ACCEPTABLE
407 HTTPStatus.PROXY_AUTHENTICATION_REQUIRED
408 HTTPStatus.REQUEST_TIMEOUT
409 HTTPStatus.CONFLICT
410 HTTPStatus.GONE
411 HTTPStatus.LENGTH_REQUIRED
412 HTTPStatus.PRECONDITION_FAILED
413 HTTPStatus.REQUEST_ENTITY_TOO_LARGE
414 HTTPStatus.REQUEST_URI_TOO_LONG
415 HTTPStatus.UNSUPPORTED_MEDIA_TYPE
416 HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE
417 HTTPStatus.EXPECTATION_FAILED
421 HTTPStatus.MISDIRECTED_REQUEST
422 HTTPStatus.UNPROCESSABLE_ENTITY
423 HTTPStatus.LOCKED
424 HTTPStatus.FAILED_DEPENDENCY
426 HTTPStatus.UPGRADE_REQUIRED
428 HTTPStatus.PRECONDITION_REQUIRED
429 HTTPStatus.TOO_MANY_REQUESTS
431 HTTPStatus.REQUEST_HEADER_FIELDS_TOO_LARGE
451 HTTPStatus.UNAVAILABLE_FOR_LEGAL_REASONS
500 HTTPStatus.INTERNAL_SERVER_ERROR
501 HTTPStatus.NOT_IMPLEMENTED
502 HTTPStatus.BAD_GATEWAY
503 HTTPStatus.SERVICE_UNAVAILABLE
504 HTTPStatus.GATEWAY_TIMEOUT
505 HTTPStatus.HTTP_VERSION_NOT_SUPPORTED
506 HTTPStatus.VARIANT_ALSO_NEGOTIATES
507 HTTPStatus.INSUFFICIENT_STORAGE
508 HTTPStatus.LOOP_DETECTED
510 HTTPStatus.NOT_EXTENDED
511 HTTPStatus.NETWORK_AUTHENTICATION_REQUIRED

 

댓글