天天看點

測試接口

curl

  • ​​download​​
  • 測試接口
# 下載下傳後直接解壓
# 環境配置:
  CURL_HOME = C:\app\curl\curl-7.66.0
# 在path中添加
  %CURL_HOME%\bin\
# cmd驗證:curl --version

# get請求
curl localhost:8080/test?name=goudan

# post請求
curl localhost:8080/addUser -X POST -d "name=goudan&age=18"

# post請求,傳遞json
curl localhost:8080/getUsers -X POST -H "Content-Type:application/json" -d '{"name":"goudan","age":"18"}'

# post請求,上傳檔案:`将D:\doc\test.png上傳到127.0.0.1:8090/log/upload接口`
curl localhost:8090/log/upload -F "file=@/doc/test.png" -H "token: test" -v

# 自定義請求頭
curl --header "Content-Type:application/json" http://example.com

# 顯示通信過程:使用 `-v`參數可以顯示一次http通信的整個過程,包括端口連接配接和http request頭資訊
      
測試接口
  • ​​參考​​

浏覽器插件

  • Edge浏覽器安裝插件
  • 測試接口
  • 測試
  • 測試接口

idea

  • ​​參考​​
  • 測試接口
    測試接口

vscode

  • ​​參考​​
  • vscode安裝插件​

    ​REST Client​

    ​​,項目根路徑下建立​

    ​stock.http​

    ​​,編寫url和請求體,點選​

    ​Send Request​

    ​,右側顯示傳回資料
# https://marketplace.visualstudio.com/items?itemName=humao.rest-client

GET https://example.com/comments/1 HTTP/1.1

POST http://dummy.restapiexample.com/api/v1/create HTTP/1.1
content-type: application/json
{
    "name":"Hendry",
    "salary":"61888",
    "age":"26"
}

# token
POST https://example.com/comments HTTP/1.1
Authorization: token xxx

# 身份驗證
GET https://httpbin.org/basic-auth/user/passwd HTTP/1.1
Authorization: Basic username:password

# 請求變量
@baseUrl = https://example.com/api
@authToken = {{login.response.headers.X-AuthToken}}

// 一個http檔案中還可以支援多個接口請求,隻需 ### 隔開即可