์ ์
๊ฐ๋ฐ์๋ผ๋ฉด ์ด์ ๋๋ ์์์ผ ํ๋ค!
๊ฐ๋ฐ์๋ผ๋ฉด ํ์๋ก ์์์ผ ํ ๊ธฐ์ด ๋คํธ์ํฌ ์ง์
๊ธฐ์ด์ ์ธ HTTP ์ต๋
๊ฐ๋ฐ์๋ก์ ์ฑ์ฅ์ ์ํด
์ํํ ์ปค๋ฎค๋์ผ์ด์
์ ์ํด
API๋ฅผ ์ ์ํ๊ฑฐ๋ ๋ค๋ฃจ๊ธฐ ์ํด
์ฑ๋ฅ ์ต์ ํ๋ ๋๋ฒ๊น
์ ์ํด
๊ฐ์ ์ค์ต ํ๊ฒฝ: VSC <- ๋ณธ์ธ์ IntelliJ๋ก ์งํ
์น> ์ธํฐ๋ท์ ํตํด ์ ๋ณด๋ฅผ ๊ณต์ ํ๊ณ ๋ค์ํ ์๋น์ค๋ฅผ ์ด์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ์๋น์ค
์นํ์ด์ง= ๋ฌธ์๋ค์ ๋ชจ์
ํ์ดํผํ
์คํธ๋ฅผ ์ด์ฉํด ์ฐ๊ฒฐ
์ธํฐ๋ท: ์ปดํจํฐ ๋คํธ์ํฌ๋ฅผ ์ฐ๊ฒฐํ๋ ๊ธ๋ก๋ฒ ๋คํธ์ํฌ ์์คํ
์น
URL: ์ธํฐ๋ท์ ์น ํ์ด์ง, ์ด๋ฏธ์ง ๋ฑ์ ๋ฆฌ์์ค ์์น๋ฅผ ๋ํ๋ด๋ ์ง์์(์ด๋ฆ) ๋๋ ๊ฒฝ๋ก
์น ์์ ์์ ์์น๋ฅผ ๋ํ๋ด๋ ์ฃผ์
IP: ์ธํฐ๋ท์ ์ฐ๊ฒฐ๋ ์ฅ์น๋ค์ ์๋ณํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ ์ซ์ ์ฃผ์
PORT: ์ปดํจํฐ ๋คํธ์ํฌ์์ IP ์ฃผ์์ ํจ๊ป ์ฌ์ฉ๋์ด, ํ๋์ ์ปดํจํฐ์์ ๋์ํ๋ ์ฌ๋ฌ ๊ฐ์ ์๋น์ค๋ ํ๋ก์ธ์ค๋ฅผ ๊ตฌ๋ถํ๋ ์ญํ
DNS(Domain Name System): ๋๋ฉ์ธ ์ด๋ฆ์ IP ์ฃผ์๋ก ๋ณํํ๋ ์์คํ
HTTP(Hypertext Transfer Protocol): ์น ๋ธ๋ผ์ฐ์ ์ ์น ์๋ฒ ๊ฐ์ ํต์ ๊ท์ฝ(ํต์ ์ฝ์)
Client (ํด๋ํฐ, ๋
ธํธ๋ถ, ๋ฐ์คํธํ)์ ์ด์ฉํด domain,URL ๋ก ์ ์ (Request)
๊ณต์ ๊ธฐ/์ค์์น๋ฅผ ํตํด ๋ผ์ฐํฐ๋ก โ ํด๋ผ์ด์ธํธ๊ฐ ์๋ฒ๋ฅผ ์ฐพ์๊ฐ๋ ค๋ฉด ์ฃผ์(IP)๊ฐ ์์ด์ผ ํ๋๋ฐ, ๊ทธ ์ฃผ์๋ DNS์ ์์ต๋๋ค
๋ผ์ฐํฐ๋ DNS์์ IP ์ฃผ์๋ฅผ ์ฐพ์์ด
๊ฐ์ข
๋ณด์์ฅ๋น ๋ฐ ๋คํธ์ํฌ ์ฅ๋น๋ฅผ ๊ฑฐ์ณ ์๋ฒ์ ์ ์
| www.naver.com | ๋๋ฉ์ธ, URL | ์ด๋ฆ |
| 105.209.222.141 | IP | ์ฃผ์ |
| 22,23,80, 443 | Port | ๋ฌธ |
์์ฒญ์ ํ๋์ ๋ฌธ์๋ก ๋ง๋ฌ(ํจํท)
HTML:๋ผ๋ (๋ฐ์ดํฐ๋ฅผ ๊ตฌ์กฐํ- ์น ์ฝํ
์ธ ์ ์๋ฏธ์ ๊ตฌ์กฐ๋ฅผ ์ ์)
CSS: ์ด (์คํ์ผ ์ํธ)
JS: ๊ทผ์ก(์น ํ์ด์ง์ ๊ธฐ๋ฅ, ์ฌ์ฉ์์ ์ํธ์์ฉ/ ๋ฐ์ดํฐ ์ปจํธ๋กค)
Python: ๋๋ ๋ฐ ์ฅ๊ธฐ(๋ฐ์ดํฐ ์ฒ๋ฆฌ, ์ฌ์ฉ์์๊ฒ ์ ๋ฌ)
ํด๋ผ์ด์ธํธ: ์๋น์ค๋ฅผ ์์ฒญํ๋ ์ปดํจํฐ(ํ๋ก๊ทธ๋จ),
์น ๋ธ๋ผ์ฐ์ ๋ฅผ ํตํด ์๋ฒ์ ์ ์ํ๋ ์ฌ์ฉ์์ ๋๋ฐ์ด์ค๋ฅผ ์๋ฏธ
์๋ฒ: ํด๋ผ์ด์ธํธ์ ์์ฒญ์ ๋ฐ๋ผ ์๋น์ค๋ฅผ ์ ๊ณตํ๋ ์ปดํจํฐ(ํ๋ก๊ทธ๋จ)
#001.py
from http.server import BaseHTTPRequestHandler, HTTPServer
import os
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/': #๊ธฐ๋ณธํ์ด์ง๋ก ์ ์๋์์ ๋
#self.path = '/index.html'
self.path = '/001.html'
try:
file_to_open = open(self.path[1:]).read() #self.path๋ฅผ ์ ๋ฌ๋ฐ์ open
self.send_response(200)
except:
file_to_open = "File not found"
self.send_response(404)
self.end_headers()
self.wfile.write(bytes(file_to_open, 'utf-8'))#์ค์ ๋ก ์ ๋ฌ๋๋ ๊ฐ(utf๋ก~)
def run(port=8080):
server_address = ('', port)
httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
print(f'Server running on port {port}')
httpd.serve_forever()
if __name__ == '__main__':
run()
Uniform Resource Identifier : ํตํฉ ์์ ์๋ณ์
Uniform: ๋ฆฌ์์ค ์๋ณํ๋ ํต์ผ๋ ๋ฐฉ์
Identifier: ๋ค๋ฅธ ํญ๋ชฉ๊ณผ ๊ตฌ๋ถํ๋๋ฐ ํ์ํ ์ ๋ณด
URI๋ ์์น, ์ด๋ฆ ๋๋ ๋ ๋ค๋ก ์ถ๊ฐ๋ถ๋ฅ
URL: ์น ์ฌ์ดํธ๋ฅผ ํ์ํ๊ธฐ ์ํด ์
๋ ฅํ๋ ์ฃผ์๋ฅผ ๋งํจ
โโ์น ์์์๋ ์ค์ง์ ์ผ๋ก ์ฃผ์๊ฐ ์๋ ์ด๋ฆ ์ญํ
/001.html๋ก ์ ์ํ๋ค๊ณ ์ค์ ๋ก ๋ถ๋ฌ์จ ๊ฐ์ด 001.html์์ ๋ณด์ฅX
โโโ ๋ณด์์ผ๋ก ์ ์ ์ฃผ์๊ฐ ๋ฐ๋ ์ ์์
if self.path == '/001.html': #001์ ์์์ฒญ
self.path = '/index.html' #index ํ์ด์ง ๋ฐํ
์น ์ฌ์ดํธ ๋ฟ๋ง์๋ ์ปดํจํฐ ๋คํธ์ํฌ์์ ์์์ ๋ชจ๋ ๋ํ๋ผ ์ ์์
(ex. 001.html ํ์ผ์ ๋ฌผ๋ฆฌ์ ์ฃผ์๋ฅผ ์นํ์ด์ง์ ๊ฒ์ํ์ ๋ ์ถ๋ ฅ๋จ)

URL ํต์ ์ ๋์ฒญ(์ค๋ํ)์ด ๊ฐ๋ฅํด //user id์ pw ๋ ๋ฃ์ง ์๋๋ค
port(ํ๋กํ ์ฝ์ ๋ฐ๋ฅธ ์ฝ์๋ num์ด ์์) : https=443 / http=80
#hash : ํ์ด์ง์ id๊ฐ
input์ name์ด query string์ key๊ฐ์ผ๋ก ๋ค์ด๊ฐ๊ณ
(name = 'username'์ด๋ผ๋ฉด username์ด ํค๊ฐ์ผ๋ก ๋ค์ด๊ฐ๋ค)
<input type="text" name="username" value="helloget">
<input type="password" name="password" value="worldget">
<input type="submit" value="Login">
```
๋ค์์ ๊ฒฝ์ฐ username=helloget&password=worldget ์ผ๋ก ๊ฐ์ด ๋์ด๊ฐ๋ค
์ค์ ๋ก username๊ณผ pw๋ get ๋ฐฉ์์ผ๋ก ๋ณด๋ด์ง ์๋๋ค!! ๋ณด์๋ฌธ์
#### serve์์ ๋ฐ์ดํฐ ์์
`004.html`
```html
<h1>login</h1>
<form action="http://127.0.0.1:8000" method="get">
<input type="text" name="username" value="helloget">
<input type="password" name="password" value="worldget">
<input type="submit" value="Login">
</form>
http://127.0.0.1:8000์ GET ๋ฐฉ์์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ผ ๊ฒ
002.py
from http.server import (
HTTPServer,
BaseHTTPRequestHandler,
) # ๊ฐ๋จํ ์๋ฒ๋ฅผ ๋ง๋ค ์ ์๋ ๋ชจ๋
from urllib.parse import urlparse, parse_qs
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self): # get ์์ฒญ ์ฒ๋ฆฌ
print(self.path)
parsed_url = urlparse(self.path) # URL ํ์ฑ
print(parsed_url)
query_params = parse_qs(parsed_url.query) # ์ฟผ๋ฆฌ ํ์ฑ-๋์
๋๋ฆฌ๋ก ๊ฐ์ ธ์ด
print(query_params)
username = query_params.get("username", [None])[
0
] # username๊ณผ password ๊ฐ์ ๊ฐ์ ธ์ด. ๊ฐ์ด ์๋ ๊ฒฝ์ฐ None์ด ๊ธฐ๋ณธ๊ฐ.
password = query_params.get("password", [None])[0]
if username and password: # 2๊ฐ ๋ชจ๋ ์กด์ฌํ๋ ๊ฒฝ์ฐ
response = f"Username: {username}, Password: {password}"
else: # ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ์๋ form
response = """
<p>์์ด๋๋ ํจ์ค์๋๊ฐ ๋น์ด์์ต๋๋ค.</p>
<form action="" method="get">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Login">
</form>
"""
self.send_response(
200
) # HTTP ์ํ์ฝ๋ ์์ฑ(200์ ์์ฒญ์ด ์ฑ๊ณต์ ์ผ๋ก ์ฒ๋ฆฌ๋์๋ค๋ ๊ฒ)
self.send_header("Content-type", "text/html") # ์๋ต์ HTML๋ก ์ก์
self.end_headers() # ํค๋ ์ ๋ณด๋ ์ฌ๊ธฐ๊น์ง ๋ง๋ฌด๋ฆฌ ํ๊ฒ ๋ค๋ ๊ฒ
self.wfile.write(response.encode("utf-8")) # ์๋ต ๋ฉ์์ง ์์ฑ
if __name__ == "__main__":
server_address = ("", 8000)
httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
print(f"Server running on port {server_address[1]}")
httpd.serve_forever()
const url = new URL(
'https://www.example.com/path/to/page?key1=value1&key2=value2#section',
);
console.log(url.protocol); // "https:"
console.log(url.hostname); // "www.example.com"
console.log(url.pathname); // "/path/to/page"
console.log(url.search); // "?key1=value1&key2=value2"
console.log(url.hash); // "#section"
๋น about:blank์ ๋น ํ์ด์ง์์ ์งํ
๋ฐ์์ ์ผํ๋ชฐ ๊ฐ์ ์ฝ๋๋ฅผ ๋ง๋ค ์ ์์
const url = 'https://eduapi.weniv.co.kr/723/product';
fetch(`${url}`)
.then((response) => {
console.log(response.status);
return response.json();
})
.then((data) => {
console.log(data);
})
.catch((error) => {
console.error('Error:', error);
});
const url = 'https://eduapi.weniv.co.kr/753/product/search';
const params = new URLSearchParams({ keyword: 'keyring' });
fetch(`${url}?${params}`)
.then((response) => {
console.log(response.status);
return response.json();
})
.then((data) => {
console.log(data);
})
.catch((error) => {
console.error('Error:', error);
});
GET ์์ฒญ์ผ๋ก ํค์๋๋ฅผ ๋ณด๋ด๋ฉด ๋ฐฑ์๋ ์๋ฒ์์ ๋ฐ์์ ๊ฒ์
ํฐ๋ฏธ๋์์ ์ค์ตํ๋ ๊ฒฝ์ฐ - pip install requests ํ์ฌ ๋ชจ๋ ์ค์น
005.py
006.py
ํด๋น๋ฌธ์์ ASCII ์ฝ๋์ ํด๋นํ๋ 16์ง์ ๊ฐ์ผ๋ก ๋์ฒด
ํด๋ผ์ด์ธํธ-์๋ฒ ๊ฐ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ๊ธฐ ์ํ ์ฝ์ (ํ๋กํ ์ฝ)
self.send_header("Content-type", "text/plain")
- html ํ์ผ์ ์ ์กํ๋๋ฐ "text/plain"๋ก ์์ฑํ๋ฉด ์ผ๋จ text๋ก ๋ณด์
๋๋ฌธ์ Content-type์ ์๋๊ฒ์ด ์ค์<< ๋ฐฑ์๋ ๊ฐ๋ฐ์๋ ํ๋ก ํธ์๋ ๊ฐ๋ฐ์๊ฐ ๋ฐ์ดํฐ๋ฅผ ์ก์ ํ ๋ ์
๋ ฅ
1) text/html
2) text/css
3) application/javascript
์ ์ธ๊ฐ์ง ํ๊ทธ๊ฐ ์์ผ๋ฉฐ ์๋ต ๋ณธ๋ฌธ์ด html, css, JS ๋ฌธ์์์ ๋ํ๋
ํ์ฌ๋ HTTP/1.1์ด ๋ง์ด ์ฌ์ฉ์ค~ ๊ณ์ ๋ฐ์ ์ค~
HTTP ์์ฒญ ๋ฉ์์ง ๊ตฌ์กฐ
GET /index.html HTTP/1.1 <!--์์ฒญ๋ผ์ธ, ํ๋กํ ์ฝ์ HTTP/1.1-->
Host: www.hojun.com <!--ํค๋-->
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
HTTP ์๋ต ๋ฉ์์ง ๊ตฌ์กฐ
HTTP/1.1 200 OK <!--์์ฒญ์ฑ๊ณต-->
Date: Fri, 29 Mar 2023 10:30:00 GMT
Server: Apache/2.4.41 (Ubuntu)
Last-Modified: Thu, 28 Mar 2023 12:00:00 GMT
Content-Type: text/html
Content-Length: 1234
Connection: keep-alive
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>์ ์ฃผ์ฝ๋ฉ๋ฒ ์ด์ค์บ ํ</title>
</head>
<body>
<h1>Welcome to ์ ์ฃผ์ฝ๋ฉ๋ฒ ์ด์ค์บ ํ</h1>
<p>์ ์ฃผ์ฝ๋ฉ๋ฒ ์ด์ค์บ ํ์ ์ค์ ๊ฒ์ ํ์ํฉ๋๋ค!</p>
</body>
</html>
008.py
** ์ค์ํ ๊ฒ
1) ๋ค์ด์จ ๋ฉ์๋ ํ์ธ
2) GET์์๋ self.path, POST์์๋ body ํ์ธ
3) Content-Type
๋น about:blank์ ๋น ํ์ด์ง์์ ์งํ
ํ๋ก ํธ์๋์์ ๋ฐ์ดํฐ๋ฅผ ์์ฒญํ๋ฉด ๋ฐฑ์๋์์ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ํ๋ฉด์ ๋ ๋๋ง(๋ฟ๋ฆผ)์ ํ์์ ์ค๋ฌด์์ ๋ง์ด ์ฌ์ฉ
์๋ JavaScript ์ฝ๋๋ก GET์ ๋ณด๋ด๋ ๊ฒ ํ์ธ
fetch('http://127.0.0.1:8000/')
.then(response => response.json())
.then(json => console.log(json))
.catch(error => console.error(error));
์๋ JavaScript ์ฝ๋๋ก POST๋ฅผ ๋ณด๋ด๋ ๊ฒ ํ์ธ
fetch('http://127.0.0.1:8000/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: 'test',
content: 'test',
}),
})
.then(response => response.json())
.then(json => console.log(json))
.catch(error => console.error(error));
002.js - ์ผํ๋ชฐ ํ์ด์ง ์ด๋ฏธ์ง ๋ ๋๋ง
ํ๋ก ํธ์๋์ ๋ฐฑ์๋์ ํ์
๋ฐฑ์๋์์๋ Content-Type์ Json์ผ๋ก ํ๊ณ - Json๋ฐ์ดํฐ๋ก URL์ ์์ฒญํ์ ๋ ๋ฐ์ดํฐ๋ฅผ ์ ์กํด์ค
<- ์ด ๋, ์ด๋ค URL๋ก ์์ฒญํด์ผ ์ด๋ค ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ์ ์๋์ง๋ API ๋ช
์ธ์์ ๊ฐ์ ๋ฌธ์๋ก ์์
005.htmlpost๋ฐฉ์๊ณผ get ๋ฐฉ์ ์ค์ต
> GET: Path์ ์ ๋ณด๊ฐ ๋ด๊น **๊ฒ์์ฐฝ ๊ตฌํ ๋ฑ**
POST: Body์ ์ ๋ณด๊ฐ ๋ด๊น **๊ทธ๋ฌ๋ฏ๋ก login์ฐฝ์ post๋ก ๋ง๋ค์ด์ผ ํจ (์ค๋ํ ๋ฐฉ์ง ๊ฐ๋ฅ)**
์์
์์๋ ์ค์ตํ์ง ์์ง๋ง ์๋์ ๊ฐ์ ํด๋ก ๋ธ๋ผ์ฐ์ ๋ฅผ ํตํ์ง ์๊ณ ์ง์ ์๋ค ๊ฐ๋ค ํ๋ Request์ Response๋ฅผ ์ ๋ถ ๋ณผ ์ ์์ต๋๋ค.
(๋ถ๋ก) ์์ด์ด์คํฌ(Wireshark)
Source: ์ถ๋ฐ์ง IP (์์ฒญ์ IP)
์ด๋ฏธ์ง ์ถ๋ ฅํ ๋ ๊ผญ ์ต์ ํ๋ ์ด๋ฏธ์ง๋ฅผ ์ฌ๋ฆฌ๊ณ ๋ฐ์ ์ ์๋๋ก!! ์๋ก ๋ถ๋ด๋๋๊น..
GET /index.html HTTP/1.1
user-agent: MSIE 6.0; Windows NT 5.0
accept: text/html; */*
cookie: name = value
referer: http://www.naver.com
host: www.paullab.co.kr
1)
host: www.paullab.co.kr
์ค์ ์ฐ๋ฆฌ๊ฐ ๋ค์ด๊ฐ์ผ ํ ํ์ด์ง๊ฐ www.paullab.co.kr/a/b/c/index.html ์ด๋ผ๋ฉด
>> GET /a/b/c/index.html HTTP/1.1 // ์์ฒญ๋ผ์ธ= ๋ฐ์ดํฐ ์ฒ๋ฆฌ ๋ฐฉ์(์์ฒญ๋ฉ์๋), ์์ฒญ ํ์ด์ง, ํ๋กํ ์ฝ ๋ฒ์
www.paullab.co.kr
2) Header
์์ฒญ:
Accept: text/html
๋์๋๋ ์๋ต : Content-Type:text/html
Cookie: HTTP ํ๋กํ ์ฝ ์์ฒด๊ฐ ์ธ์ ์ ์ ์งํ์ง ์๋ State-less(์ ์์ํ๋ฅผ ์ ์งํ์ง ์๋) ๋ฐฉ์์ด๊ธฐ ๋๋ฌธ์ ๋ก๊ทธ์ธ ์ธ์ฆ์ ์ํ ์ฌ์ฉ์ ์ ๋ณด๋ฅผ ๊ธฐ์ตํ๋ ค๊ณ ๋ง๋ ์ธ์์ ์ธ ๊ฐ. ์ฆ ์ฌ์ฉ์๊ฐ ์ ์์ ์ธ ๋ก๊ทธ์ธ ์ธ์ฆ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์๋ค๋ ๊ฒ์ ํ๋จํ๊ณ ์ ์ฌ์ฉ.
Referer: ํ์ฌ ํ์ด์ง ์ ์ ์ ์ ์ด๋ ์ฌ์ดํธ๋ฅผ ๊ฒฝ์ ํ๋์ง ์๋ ค์ฃผ๋ ๋๋ฉ์ธ ํน์ URL ์ ๋ณด
host: ์ฌ์ฉ์๊ฐ ์์ฒญํ ๋๋ฉ์ธ ์ ๋ณด
GET
POST
PUT
DELETE
PATCH
JavaScript์ Fetch API๋ฅผ ์ฌ์ฉํ์ฌ GET ์์ฒญ์ ๋ณด๋ด๋ ์์ ์ฝ๋
fetch('https://eduapi.weniv.co.kr/753/product', {
method: 'GET' //์๋ต๊ฐ๋ฅ
})
.then(response => response.json())
.then(data => {
console.log('์ฑ๊ณต:', data);
})
.catch(error => {
console.error('์คํจ:', error);
});
POST ๋ฉ์๋๋ ์๋ฒ์ ์๋ก์ด ๋ฆฌ์์ค๋ฅผ ์์ฑํ ๋ ์ฌ์ฉ๋ฉ๋๋ค. ์์ฒญ ํจํท์ ๊ตฌ์กฐ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
POST /753/product HTTP/1.1
Host: https://eduapi.weniv.co.kr/
Content-Type: application/json
Content-Length: 1560
{
"id": 8,
"productName": "hello world keyring",
"price": 12500,
... ์๋ต ...
}
const data = {
"id": 8,
"productName": "hello world keyring",
"price": 12500,
"stockCount": 100,
"thumbnailImg": "asset/products/img/1/thumbnailImg.jpg",
"option": [],
"discountRate": 0,
"shippingFee": 1500,
"detailInfoImage": [
"asset/products/detail/2/detail1.png",
"asset/products/detail/2/detail2.png",
],
"viewCount": 0,
"pubDate": "2222-02-28",
"modDate": "2222-02-28",
}
fetch("https://eduapi.weniv.co.kr/753/product", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),//๋ฐ์ดํฐ๋ฅผ ๋ฌธ์์ด๋ก ๋ณ๊ฒฝํด์ ์์ฑ
})
.then(response => response.json())
.then(data => {
console.log("์ฑ๊ณต:", data);
})
.catch(error => {
console.error("์คํจ:", error);
});
๋ฐ์ดํฐ ์์ฑ ํ์ธ์ GET ์์ฒญ์ผ๋ก ํ์ธ
fetch('https://eduapi.weniv.co.kr/753/product', {
method: 'GET'
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
์๋ฒ์ ์ด๋ฏธ ์กด์ฌํ๋ ๋ฆฌ์์ค๋ฅผ ์์ ํ ๋ ์ฌ์ฉ
์ด ๊ฒฝ์ฐ ์๋์ ๊ฐ์ด ์ธ์ฆ ๊ฐ๊น์ง ํจ๊ป ๋ค์ด๊ฐ ์๊ฒ ๋ฉ๋๋ค. ์ฌ๊ธฐ์๋ ์ธ์ฆ์ ์ฃผ์์ฒ๋ฆฌ
PUT /753/product HTTP/1.1
Host: https://eduapi.weniv.co.kr/
Content-Type: application/json
Content-Length: 1559
Authorization: ํ ํฐ๊ฐ
{
"id": 1,
"productName": "test put data",
"price": 999999,
... ์๋ต ...
}
const data = {
"id": 1,
"productName": "test put data",
"price": 999999,
"stockCount": 100,
"thumbnailImg": "asset/products/img/1/thumbnailImg.jpg",
"option": [],
"discountRate": 0,
"shippingFee": 1500,
"detailInfoImage": [
"asset/products/detail/2/detail1.png",
"asset/products/detail/2/detail2.png",
],
"viewCount": 0,
"pubDate": "2022-02-28",
"modDate": "2022-02-28",
}
// const token = "your_bearer_token_here";
fetch("https://eduapi.weniv.co.kr/753/product/1", {
method: "PUT",
headers: {
"Content-Type": "application/json",
// "Authorization": `Bearer ${token}`,
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
DELETE /753/product/1 HTTP/1.1
Host: https://eduapi.weniv.co.kr/
Authorization: ํ ํฐ๊ฐ
const productId = 1;
// const token = "your_bearer_token_here";
fetch(`https://eduapi.weniv.co.kr/753/product/${productId}`, {
method: "DELETE",
// headers: {
// "Authorization": `Bearer ${token}`,
// },
})
009.py
006.html post ๋ฐฉ์์ผ๋ก username๊ณผ pw ์ ์ก
vsc์์ live server ์ค์นํด์ ๊ตฌ๋ํ์ธํ๊ธฐ
MIME ; ์ด๋ฉ์ผ์ ์ํด ๊ฐ๋ฐ๋
์๋ฒ๊ฐ ์์ฒญ์ ์ด๋ป๊ฒ ์ฒ๋ฆฌํ๋์ง ์ ์ ์์
์ฃผ์ ์ํ์ฝ๋๋ง ์์๋๊ธฐ
์ค์บ๋ ๊ณต๊ฒฉ // ํด์ปค์ ํํ๋ฆฐํ
์ ๋ฐฉํดํ๊ธฐ ์ํด ๋ฉ์์ง์ ํผ๋์ ์ฃผ๊ธฐ๋ ํจ (๋ฐฑ์๋ ๊ฐ๋ฐ์๊ฐ ์์๋ก ์ํ์ฝ๋๋ฅผ custom ๊ฐ๋ฅ) --> ์ซ์๋ ์ซ์์ผ ๋ฟ ! ์ด๋ค! ํ์ง๋ง ์ํ์ฝ๋์ ๋ฌธ์ ๋ ์์์ผ ํจ
401 ์ธ์ฆ์ ๋ณด๊ฐ ์๋ชป ๋์ ๋
5XX err = ๋ฐฑ์๋ ๊ฐ๋ฐ์์๊ฒ ์ค์ํ ์ค๋ฅ
์๋ฒ ์ค๋ฅ
์ค์ต 10.py
๊ณผ์ ํด๋ณด๋ ๊ฒ์ด ์ข์..!
์ธํฐ๋ท ํต์ ์ ์ํ ๊ธฐ๋ณธ ํ๋กํ ์ฝ ์ค์ํธ
๋ฐ์ดํฐ๋ฅผ ํจํท์ผ๋ก ๋๋์ด ์ ์กํ๊ณ ์์ ์ธก์์ ์ฌ์กฐ๋ฆฝ
์ฒ์๋ถํฐ ํ๋กํ ์ฝ์ด ์์์XX, ํ์ฌ๊ฐ ๋ค๋ฅธ ์ฅ๋น๊ฐ์ ํธํ๋ฌธ์ ๋ฅผ ํด๊ฒฐ
4๊ณ์ธต๊ณผ OSI7๋ ์ด์ด๋ ํํ๋ฐฉ์์ ์ฐจ์ด์ผ ๋ฟ ํต์ ํ๋ก์ธ์ค๋ ๊ฐ์
TCP/IP 4๊ณ์ธต...
1)๋คํธ์ํธ
2)์ธํฐํ์ด์ค,์ธํฐ๋ท
3)์ ์ก
4)์์ฉ
7๊ณ์ธต) ๋ฌผ๋ฐ๋ค์ ์ธํ์
์ก์ ์ธก --๊ฐ ๊ณ์ธต์์ ํค๋๊ฐ ์ถ๊ฐ๋จ
1) APP ๊ณ์ธต (ํธ์ง์์ฑ)
2) ํธ๋์คํฌํธ ๊ณ์ธต (ํธ์ง๋ฅผ ํ์ด์ง๋ก ๋๋)
TCP : 3-way handshake๋ฅผ ํตํด ์ฐ๊ฒฐ ์ค์
ํ๋ฆ์ ์ด, ํผ์ก์ ์ด, ์ค๋ฅ์ ์ด
UDP : ์ ๋ขฐ์ฑ ๋ณด์ฅX, ๋น ๋ฆ
3) ์ธํฐ๋ท ๊ณ์ธต
4) ๋คํธ์ํฌ ์ธํฐํ์ด์ค ๊ณ์ธต
์์ ์ธก -- ๊ฐ ๊ณ์ธต์์ ํค๋๋ฅผ ๋ฒ๊ฒจ๋
1) ๋คํธ์ํฌ ์ธํฐํ์ด์ค ๊ณ์ธต (ํธ์ง ์์ )
2) ์ธํฐ๋ท ๊ณ์ธต (๋ดํฌ์์ ํ์ด์ง ๊บผ๋ด๊ธฐ)
3) ํธ๋์คํฌํธ ๊ณ์ธต (ํ์ด์ง ์ฌ์กฐ๋ฆฝ)
4) ์ ํ๋ฆฌ์ผ์ด์
๊ณ์ธต (ํธ์ง ์ฝ๊ธฐ)
์ก์ ์ธก
์น๋ธ๋ผ์ฐ์ ์์ ์ฃผ์๋ฅผ ์
๋ ฅ <-- ํ๋์ ๋ฉ์์ง๋ก ์์ฑ๋จ
ํธ๋์คํฌํธ๊ณ์ธต์์ ๋ฉ์์ง๊ฐ ์๋ฆผ (ํจํท์ผ๋ก ๋ถํด)
์ํ๋ฅผ ์ ์งํ๋ ๊ฒ(์ํ) / ์ ์งํ์ง ์๋ ๊ฒ (๋ฌด์ํ)
์๋ฒ๊ฐ ํด๋ผ์ด์ธํธ์์ ํต์ ์์ ์ํ ์ ๋ณด๋ฅผ ์ ์งํ๋์ง ์ฌ๋ถ
Stateful(์ํ์ ์ง)
HTTP: ์ํ์ ์ง ์ํจ
์ด๊ฑธ ์ด๋ป๊ฒ ์ํ ์ ์ง์ํค๋์ง?
Stateless(๋ฌด์ํ)
๋ด์ฉ ๊ณต์ <-- ์๋ฒ ๋ณ๊ฒฝํด๋ ๊ฐ๋ฅ
HTTP: ์ํ์ ์ง ์ํจ -- ์ฟ ํค, ์ธ์
, ํ ํฐ ๋ฑ์ ๋งค์ปค๋์ฆ์ ์ฌ์ฉํด ์ํ์ ๋ณด๋ฅผ ์ ์ง
token์ ๋ํ ๊ณต๋ถ..
์ํ์ ์ง์ ์ ์ฐจ ~ JWT๊ณต๋ถํ๋๊ฒ๋ ์ข์ ๋ฏ!
1) ํด๋ผ์ด์ธํธ ๋ฐฉ๋ฒ:์ฟ ํค, ๋ก์ปฌ ์คํ ๋ฆฌ์ง 2)์๋ฒ: ์ธ์
ํ ๊ธฐ์ ์ ์ฌ์ฉํ๊ธฐ ๋ณด๋ค๋ ์ฌ๋ฌ ๊ธฐ์ ์ mixํด ์ฌ์ฉ
๊ฐ ๋ฐฉ๋ฒ์ด ์๋ฒฝํ์ง ์์
์ ํ์ผ์ด์
์ ์๊ตฌ์ฌํญ์ ๋ง๊ฒ, ํ๋ ์์ํฌ์ ๊ถ์ฅ ๋ฐฉ๋ฒ์ ๋ง๊ฒ ์ฌ์ฉ
์น๋ธ๋ผ์ฐ์ ์ ์ ์ฅ๋๋ ์์ ํ
์คํธ ํ์ผ
ํค-๊ฐ ์์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์ฅ
ํด๋ผ์ด์ธํธ์์ id/pw ์ ๋ฌํ๋ฉด ์๋ฒ์์ ์ฟ ํค ์ ๋ฌ
ํด๋ผ์ด์ธํธ๋ ์์ฒญ ์ ์ฟ ํค๊ฐ๊ณผ ํจ๊ป ์ ๋ฌ (์์ฒญ+์ฟ ํค)
id/pw ์ฌ์
๋ ฅ ํ์ ์์!
์ฟ ํค์ญ์ ์ ์ด๋ฆ๊ณผ ๊ฒฝ๋ก๋ฅผ ์ ํํ ์ง์ ํด์ผ ํจ
๋ณด์์ ๋ฏผ๊ฐํ ์ ๋ณด๋ ์ฟ ํค์ ์ ์ฅํ์ง ์๋๊ฒ ์ข์
์น ๋ธ๋ผ์ฐ์ ์์ ์ ๊ณตํ๋ ์ ์ฅ์
๋ง๋ฃ๊ธฐ๊ฐ์ด ์์
ํฌ๋ก์ค ์ฌ์ดํธ ์คํฌ๋ฆฝํ
(XSS) ๊ณต๊ฒฉ์ ์ทจ์ฝ
์๋ฒ์ธก์์ ์ ์ํ ์ฌ์ฉ์์ ๋ํ ์ ์ ์ ๋ณด๋ฅผ ์ ์ฅํ๊ณ ์๋ค!
SSL/TLS ํ๋กํ ์ฝ์ ์ฌ์ฉํด ํต์ ๋ด์ฉ์ ์ํธํ
์ค๊ฐ์ ๊ณต๊ฒฉ
์ค๋ฌด์์๋ API ๋ช
์ธ๋ฅผ ๊ฐ์ง๊ณ ํ๋ก ํธ์๋ ๊ฐ๋ฐ์์ ๋ฐฑ์๋ ๊ฐ๋ฐ์๊ฐ ํ์
-- ๋ฌธ์์์
์ ๋ฐฑ์๋์์
์ค์จ๊ฑฐ
--
๋ฐ์ดํฐ, ๋คํธ์ํฌ์ ๋ํด ๊ณต๋ถํ๋ค.
๋ถ๋๋ฝ๊ฒ๋ ์ง๊ธ๊น์ง ๊ฐ๋ฐ์ ํ๋ฉด์ ์ฝ๋์๋ง ์ ๊ฒฝ์ผ์ง ์คํ๋ก์ง์ ๋ํด์๋ ๋ฐฐ์์ผ๊ฒ ๋ค ๊ด์ฌ๋์ง ์์๋๋ฐ ์ธํ๋ฐ์์ ๊ฐ์๋ฅผ ๋ค์ผ๋ฉฐ CS๊ณต๋ถ์ ์ค์์ฑ์ ๋ํด ์๊ฐํ๊ณ ์ ๋ฆฌํ๋ ๊ธฐํ๊ฐ ๋์๋ค.
ํนํ ์น๊ฐ๋ฐ์ ๊ฐ์ธ์ผ๋ก๋ง ๊ณต๋ถํ์ง๋ง, ์ด๋ฒ์๋ ํ์
์ ์ปค๋ฎค๋์ผ์ด์
์ ์ํ ๊ณต๋ถ๊ฐ ๋์์ต๋๋ค.