SystemsComputer Networks
HTTP & DNS
กลไกการทำงานของ Web Protocols เบื้องต้น
HTTP & DNS (สรุปด่วน)
1. HTTP (HyperText Transfer Protocol)
ทำงานอยู่บน L7 (Application Layer) เป็น Protocol หลักที่ใช้บน World Wide Web แบบ Request-Response
- Stateless: Server ไม่จดจำสถานะของ Client ใน Request ก่อนหน้า (จึงต้องใช้
CookiesหรือTokensเพื่อยืนยันตัวตน) - HTTP Methods:
GET: ขอข้อมูล (Read)POST: ส่งข้อมูลไปสร้างใหม่ (Create)PUT/PATCH: อัปเดตข้อมูล (Update)DELETE: ลบข้อมูล (Delete)
- Status Codes หลัก:
2xx: Success (เช่น200 OK,201 Created)3xx: Redirection (เช่น301 Moved Permanently)4xx: Client Error (เช่น400 Bad Request,401 Unauthorized,404 Not Found)5xx: Server Error (เช่น500 Internal Server Error,502 Bad Gateway)
2. DNS (Domain Name System)
สมุดโทรศัพท์ของ Internet
- หน้าที่: แปลง Human-Readable Domain (เช่น
google.com) ไปเป็น IP Address (เช่น142.250.190.46) ที่ Computer ใช้คุยกันผ่าน L3 (Network Layer) - DNS Resolution Flow:
- Browser Cache (เช็คเครื่องตัวเองก่อน)
- OS Cache (ไฟล์
hosts) - Router Cache
- ISP Recursive DNS Server
- วิ่งไปถาม Root Server -> TLD Server (
.com) -> Authoritative Server จนได้ IP กลับมา