Http協議

定義前後端溝通時 ,要遵守的規則

  1. 負責規定資料的傳輸格式 ,讓前端和後端能夠有效地進行資料溝通
  2. 可以分成 request(請求) 和 response(回應) 兩部分

一次http溝通(包含一個request 和一個 response)

Http Request(請求)

  • http method (http 請求方法) ex: 常用的有GET ,POST ,PUT ,DELETE ,…等
  • url 瀏覽器中的網址 ex: http://localhost:8080/test
  • request header 放一些通用的資訊
  • request body 放請求參數 (只有在使用POST和PUT時才能使用)

Http Response(回應)

  • http status code (http狀態碼 ,用來表示請求結果) 1xx: 資訊 2xx: 成功 3xx: 重新導向 4xx: 前端請求錯誤 5xx: 後端處理有問題
  • response header 放一些通用的資訊 (Content-type:text/plain)
  • response body 放後端返回的數據 ex: Hello World!