[計算機網路03] Web 與 HTTP 協定的應用層結構


Posted by RexWei1016 on 2025-04-08

🌐 第四節:The Web(網頁服務)

📌 基本概念:

Web 的運作是建立在 HTTP(Hypertext Transfer Protocol) 上,屬於應用層協定。

🎯 HTTP 是什麼?

  • HTTP 是一種無狀態(stateless)協定,用來傳遞 HTML、圖片、JSON、XML 等網頁內容。
  • 使用 TCP Port 80(或 HTTPS 使用 443)

🧭 一次網頁請求的流程(Client-Server 架構):

1. 使用者開啟瀏覽器,輸入網址 → 產生 HTTP Request
2. Request 發送至 Web Server(如 Apache、Nginx)
3. Web Server 回傳 HTTP Response(HTML 或 JSON)
4. 瀏覽器解析並顯示畫面

📩 HTTP 請求與回應的內容

HTTP Request(由 Client 發出)

包含以下欄位:

GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html

HTTP Response(由 Server 回應)

包含以下欄位:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1024

<html>...</html>

🔄 常見的 HTTP 方法(Methods):

方法 功能
GET 取得資源
POST 新增資源
PUT 更新資源
DELETE 刪除資源

💡 現代 Web 與 Application 層的結合

以你熟悉的 React + API 架構為例:

  • React:在 Client 端實作 Presentation Logic
  • Express、ASP.NET、Spring Boot 等後端伺服器:負責 Application Logic
  • 資料庫(PostgreSQL, SQL Server 等):儲存 Data Storage

React 發出 HTTP Request → API Server 處理邏輯並回應資料


📧 第五節:Email(電子郵件)傳輸架構

Email 是另一個典型的應用層服務,底層使用 SMTP、IMAP 或 POP 協定。

📤 Email 傳送流程(2-tier, 厚客戶端):

  1. 使用者在 Outlook 編寫郵件
  2. 使用 SMTP 發送郵件到發信者郵件伺服器
  3. 發信伺服器使用 SMTP 將郵件轉發到收件者郵件伺服器
  4. 收件者使用 IMAP 或 POP 從郵件伺服器下載郵件

📥 Email 傳送流程(3-tier, Webmail):

像 Gmail 的流程如下:

  1. Client 使用 HTTP 向 Webmail Server 發送請求
  2. Webmail Server 使用 SMTP 發信
  3. 接收端 Mail Server 儲存郵件
  4. Client 使用 HTTP → Webmail Server → 使用 IMAP 讀取郵件

📦 SMTP 封包格式(RFC 822)

Header:
To: someone@example.com
From: you@example.com
Subject: Meeting Update

Body:
Hello, the meeting has been moved to 3PM.

🧩 附加檔案怎麼傳?

SMTP 原生只支援 ASCII 純文字,不能傳圖片、檔案。

所以需使用 MIME(Multipurpose Internet Mail Extensions)

  • 發信端將檔案轉成 ASCII
  • 收信端用 MIME 解碼恢復原檔案

🧪 應用層協定延伸(Other Protocols)

協定 功能 範例工具
FTP 檔案傳輸 FileZilla
Telnet/SSH 遠端終端機連線 PuTTY
IRC/XMPP 即時通訊 Discord、Slack
DNS 網域名稱轉換為 IP nslookup, dig

📈 第六節:管理觀點(Implications for Management)

  • 現代企業必須管理大量應用層服務
  • 架構選擇(如 client-server 或 cloud)會影響:
    • 成本
    • 可維護性
    • 可擴展性(Scalability)
    • 安全性

#計算機網路







Related Posts

this 與 call() / apply() / bind()

this 與 call() / apply() / bind()

BoF 理論簡介(1)

BoF 理論簡介(1)

現代前端工具

現代前端工具


Comments