--- title: 2019 夏令營 網路 / HTTP / RESTful 觀念及實做 共筆 tags: SITCON Camp 2019 課程共筆, SITCON, 夏令營, 共筆 GA: UA-34467841-15 --- # 網路 / HTTP / RESTful 觀念及實做 - [投影片](https://denny.one/the-net/) # History [History of the Internet](https://zh.wikipedia.org/wiki/%E4%BA%92%E8%81%94%E7%BD%91%E5%8E%86%E5%8F%B2) [How Browsers Work?](https://github.com/alex/what-happens-when) >請去看英文[name=Denny Huang] ## OSI Model ::: info 英文全名:**O**pen **S**ystem **I**nterconnection Reference Model 中文全名:開放式系統互連通訊參考模型 ::: [OSI wiki](https://zh.wikipedia.org/wiki/OSI%E6%A8%A1%E5%9E%8B) 七層( [白雪公主與七個小矮人](https://www.explainxkcd.com/wiki/index.php/1417:_Seven) ) * __第一層__ 實體層( Physical Layer ) * __第二層__ 資料連結層( Data Link Layer ) * __第三層__ 網路層( Network Layer ) * __第四層__ 傳輸層( Transport Layer ) * __第五層__ 會議層( Session Layer ) * __第六層__ 表達層( Presentation Layer ) * __第七層__ 應用層( Application Layer ) ### Details: ### Tools * Wireshark * terminal-tool * dig * cn * curl * jq * python3-http.server * chrome extension * JSON Viewer #### 實體層( _Physical Layer_ ) * Network interface:網路卡 * ipv4: 255.255.255.255 * class a: 0.0.0.0 ~ 127.0.0.0 * ipv6(RFC 3363): * Private IP (內網ip) * Public IP (外網ip = 公開的) * 打開terminal 輸入 * `ip a` * `mtr google.com` 看路由 * Port: * ~1024: Admin only * 8080: #### 資料連結層( _Data Link Layer_ ) #### 網路層( _Network Layer_ ) #### 傳輸層( _Transport Layer_ ) #### 會議層( _Session Layer_ ) #### 表達層( _Presentation Layer_ ) #### 應用層( _Application Layer_ ) #### TCP/UDP * Pratice: `nc -lvp <port>` / `nc -v <host_ip><port>` ``` l: listen v: verbose u: use UDP p: assign port ``` * Wireshark: `ip.addr == <destination_IP>` * 限定只顯示該IP傳過來的封包內容 * **TCP** : [傳輸控制協定 (**T**ransmission **C**ontrol **P**rotocol)](https://zh.wikipedia.org/wiki/%E4%BC%A0%E8%BE%93%E6%8E%A7%E5%88%B6%E5%8D%8F%E8%AE%AE) * 三向交握(three-way handshake) * SYN / ACK ``` client -> SYN -> server client <- SYN/ACK <- server cilent -> ACK -> server cilent <-messenge -> server ``` * 謹慎的連線 * **UDP** : 用戶資料報協定(**U**ser **D**atagram **P**rotocol) * 不謹慎,但快速的連線 >TCP 會讓你好好把話講完 >UDP 是講就對了 [name=Denny Huang] #### DNS * 解析域名 * ```bash dig www.google.com ``` 從`;; ANSWER SECTION:`找到 IP 可以直接連 #### HTTP :::info 英文全名: **H**yper **T**ext **T**ransfer **P**rotocol ::: * Status code [[ Http status code list ] - neko (ΦωΦ)](https://http.cat) * 2xx: 成功( Success ) * 3xx: 重新導向( Redirection ) * 4xx: 客戶端錯誤( Client Error ) * 5xx: 伺服器錯誤( Server Error ) * Request headers * User-Agent: 可偽造 * Response headers * `curl` command ```bash curl -v <IP>:<port> ``` * Example 1: * Code: ```bash curl -v <IP>:<port> ``` * Result: ```bash GET / HTTP/1.1 Host: 192.168.3.112:8080 User-Agent: curl/7.65.3 Accept: */* ``` * Example 2: * First open python default http server ( port 8000 ) ```bash python3 -m http.server ``` :::danger :exclamation:警告:不要在重要目錄開 http.server:exclamation: ::: * Then use curl ```bash curl -v localhost:8000 ``` #### HTTPS :::info 英文全名:**H**yper **T**ext **T**ransfer **P**rotocol **S**ecure ::: * http 是明碼傳輸 * https 則是加密傳輸 * Cookie / Session * Cookie 可僞造  * Session 推薦使用 * Session ID is cookie  #### API :::info 英文全名:**A**pplication **P**rograming **I**nterface ::: * 資料傳遞 #### RESTful * GET -> 取得資料 * POST -> 送出資料 * PUT -> 更新資料 * DELETE -> 刪除資料 * And More... #### Data type * XML ( 舊式資料結構 ) :::info 英文全名: **Ex**tensible **M**arkup **L**anguage ::: * 繁瑣 * 很繁瑣 * 超繁瑣 * 神繁瑣 * JSON :::info 英文全名: **J**ava**S**cript **O**bject **N**otation ::: * recommended * 經過包裝 * 類似於 `Python Dict` 的結構 * Example: ```bash curl -g https://api2019.coscup.org/programs.json | jq . ``` ## IETF / RFC [IETF ( 網際網路工程任務組 )](https://zh.wikipedia.org/zh-tw/%E4%BA%92%E8%81%94%E7%BD%91%E5%B7%A5%E7%A8%8B%E4%BB%BB%E5%8A%A1%E7%BB%84) [RFC ( 收集了有關網路相關資訊 )](https://zh.wikipedia.org/wiki/RFC) * [RCF 2324](https://tools.ietf.org/html/rfc2324) - 愚人節 * [RCF 2468](https://tools.ietf.org/html/rfc2468) - 訃聞 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up