HTTP 정리

Rotti_Kim·2022년 12월 7일
0

WEB 공부

목록 보기
3/4

HTTP란?

웹 상에서 웹 서버 및 웹브라우저 상호 간의 데이터 전송을 위한 응용계층 프로토콜을 의미한다.

  • 처음에 www 상의 하이퍼텍스트 논문과 같은 문서를 전달하는데 주로 이용
  • 기술이 발달함에 따라 이미지, 음성 등 거의 모든 형식의 데이터 전송이 가능해짐

HTTP 특징

  • 클라이언트(Request) - 서버(Response) 모델로 동작

HTTP 헤더

HTTP 메소드

Rest

HTTP 데이터 전송 방식

클라이언트가 HTTP 요청 메시지를 통해 서버에 데이터를 전송하는 방법은 크게 3가지 방식

이하의 3가지 방식으로 클라이언트가 보내는 모든 요청 데이터를 받을 수 있다.

https://maenco.tistory.com/entry/HTTP-Request-Data요청-데이터

1. 쿼리 파라미터(HTTP GET)

  • url의 쿼리 파라미터에 데이터를 포함해서 전달하는 방식이다.
  • 클라이언트에게 집접적으로 정보가 노출되므로 민감한 정보는 제외해야 한다.
  • 쿼리 파라미터는 message body가 아닌 url을 통해 데이터를 전송하기 때문에 content-type 이 없다.
  • get 방식을 사용하여전송하는 쿼리 파라미터는 ? 시작으로 보냄
  • key=value형식이며 추가 파라미터는 & 이용해서 구분한다 (만일 키값 중복일시 앞에가 우선)

예시: 검색, 필터, 페이징

*쿼리: 데이터베이스에 정보를 요청하는 것

2. Form (HTTP POST)

  • HTML의 form태그를 활용하여 서버로 데이터를 전송하는 방식
  • key=value 형식으로 message body에 전송

<전송 형식>

<form action="/request-param" method="post">
	username: <input type="text" name="username" /> 
	age: <input type="text" name="age" /> 
	<button type="submit">전송</button>
</form>

//전송 예시
username=kim&age=20

<HTTP 메시지>

content-type : application/x-www.form-urlencoded //메시지 바디의 데이터 형식을 지정
message body : username=kim&age=20

*message body: html 바디 메시지바디와 엔티티 바디는 기본적으로 같지만 코드가 적용된 엔티티 바디는 내용이 변함.

3. Message body

  • HTTP Message body에 데이터 자체를 넣어서 보내는 방법
content-type : text/plain
message body : hello

//출력 예시
System.out.println("messageBody = " + messageBody);
message body = hello

4. JSON

  • JSON포맷으로 데이터를 서버에 전송
  • 전송된 텍스트를 객체처럼 활용
  • 주로 API에 활용

데이터 전달 방식

https://aejeong.com/entry/05-HTTP-웹-기본-지식-클라이언트에서-서버로-데이터-전송

크게 2가지로 나눈다.

  1. 쿼리 파라미터를 통한 데이터 전송

    - GET
    - 주로 정렬 필터(검색어)

  2. 메시지 바디를 통한 데이터 전송

    - POST, PUT, PATCH

    - 회원 가입, 상품 주문, 리소스 등록, 리소스 변경

쿠키와 세션

Content-Type

1) Multipart Related MIME 타입

- Content-Type: Multipart/related <-- 기본형태

- Content-Type: Application/X-FixedRecord

2) XML Media의 타입

- Content-Type: text/xml

- Content-Type: Application/xml

- Content-Type: Application/xml-external-parsed-entity

- Content-Type: Application/xml-dtd

- Content-Type: Application/mathtml+xml

- Content-Type: Application/xslt+xml

3) Application의 타입

- Content-Type: Application/EDI-X12 <-- Defined in RFC 1767

- Content-Type: Application/EDIFACT <-- Defined in RFC 1767

- Content-Type: Application/javascript <-- Defined in RFC 4329

- Content-Type: Application/octet-stream : <-- 디폴트 미디어 타입은 운영체제 종종 실행파일, 다운로드를 의미

- Content-Type: Application/ogg <-- Defined in RFC 3534

- Content-Type: Application/x-shockwave-flash <-- Adobe Flash files

- Content-Type: Application/json <-- JavaScript Object Notation JSON; Defined in RFC 4627

- Content-Type: Application/x-www-form-urlencode <-- HTML Form 형태

* x-www-form-urlencode와 multipart/form-data은 둘다 폼 형태이지만 x-www-form-urlencode은 대용량 바이너리 테이터를 전송하기에 비능률적이기 때문에 대부분 첨부파일은 multipart/form-data를 사용하게 된다.

4) 오디오 타입

- Content-Type: audio/mpeg <-- MP3 or other MPEG audio

- Content-Type: audio/x-ms-wma <-- Windows Media Audio;

- Content-Type: audio/vnd.rn-realaudio <-- RealAudio; 등등

5) Multipart 타입

- Content-Type: multipart/mixed: MIME E-mail;

- Content-Type: multipart/alternative: MIME E-mail;

- Content-Type: multipart/related: MIME E-mail <-- Defined in RFC 2387 and used by MHTML(HTML mail)

- Content-Type: multipart/formed-data <-- 파일 첨부

6) TEXT 타입

- Content-Type: text/css

- Content-Type: text/html

- Content-Type: text/javascript

- Content-Type: text/plain

- Content-Type: text/xml

7) file 타입

- Content-Type: application/msword <-- doc

- Content-Type: application/pdf <-- pdf

- Content-Type: application/vnd.ms-excel <-- xls

- Content-Type: application/x-javascript <-- js

- Content-Type: application/zip <-- zip

- Content-Type: image/jpeg <-- jpeg, jpg, jpe

- Content-Type: text/css <-- css

- Content-Type: text/html <-- html, htm

- Content-Type: text/plain <-- txt

- Content-Type: text/xml <-- xml

- Content-Type: text/xsl <-- xsl

profile
세상의 문제를 기술적으로 해결하는 공학자

0개의 댓글