Programming/Network (๋„คํŠธ์›Œํฌ)

[์›น] HTTP ์š”์ฒญ(Request) ์ƒ์„ธ ์ •๋ณด

MOONCO 2022. 6. 30. 18:10

๐Ÿ‘‰ HTTP ์š”์ฒญ

 

๐Ÿšฉ ์ƒ๊น€์ƒˆ, ๋ชจ์–‘

headers: {
  'Content-Type': 'application/json'
  'method': 'POST',
  'mode': 'cors',
  'cache': 'no-cache',
  'credentials': 'same-origin',
  'Authorization': 'Bearer eJfwefnwfewfnfwlalknvo23fdsnewflj'
},
body: JSON.stringify({data})

 

๐Ÿšฉ Body

ํด๋ผ์ด์–ธํŠธ๊ฐ€, ์„œ๋ฒ„์—๊ฒŒ ๋ณด๋‚ด๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด๋Š” ๊ณณ

 

๐Ÿšฉ Headers

Body์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์„ค๋ช…ํ•˜๋Š” ๊ณณ

 

1. Content-type

HTTP ์š”์ฒญ์— ๋“ค์–ด๊ฐ€๋Š” body์˜ ํƒ€์ž…์„ ์„ค์ •ํ•œ๋‹ค.
// Content-Type : application/x-www-form-url
// Content-Type : text/plain
// Content-Type : multipart - body๊ฐ€ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ํƒ€์ž…์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ง
// Content-Type : multipart/form-data - body๊ฐ€ HTML <form>์˜ ์—ฌ๋Ÿฌ ํƒ€์ž…์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ง

headers: {
  'Content-Type': 'multipart/form-data'
},

 

* HTML Form์˜ ์†์„ฑ

name : form์˜ ์ด๋ฆ„

action : form์ด ์ „์†ก๋˜๋Š” ์„œ๋ฒ„ url / html link

method : ์ „์†ก ๋ฐฉ๋ฒ• ( get, post, ... )

autocomplete : ์ž๋™ ์™„์„ฑ

* enctype : ํผ ๋ฐ์ดํ„ฐ์˜ ์ธ์ฝ”๋”ฉ ๋ฐฉ์‹ ์ง€์ • ( ์š”์ฒญ Content-Type ์ง€์ • ๋ถ€๋ถ„ )

- application/x-www-form-url : default๊ฐ’, ๋ชจ๋“  ๋ฌธ์ž ์ธ์ฝ”๋”ฉ

- text/plain : ๊ณต๋ฐฑ๋ฌธ์ž '+'๋กœ ๋ฐ”๊ฟˆ, ๋ฌธ์ž ์ธ์ฝ”๋”ฉ ์•ˆํ•จ

- multipart/form-data : ๋ฌธ์ž ์ธ์ฝ”๋”ฉ ์•ˆํ•จ

 

๋ฐ˜์‘ํ˜•