get request uni 参数_接口测试实战| GET/POST 请求区别详解
生活随笔
收集整理的這篇文章主要介紹了
get request uni 参数_接口测试实战| GET/POST 请求区别详解
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在日常的工作當中,HTTP 請求中使用最多的就是 GET 和 POST 這兩種請求方式。深度掌握這兩種請求方式的原理以及異同之處,也是之后做接口測試一個重要基礎(chǔ)。
GET、POST 的區(qū)別總結(jié)
演示環(huán)境搭建
為了避免其他因素的干擾,使用 Flask 編寫一個簡單的 Demo Server。
hello.py
from?flask?import?Flask,?requestapp?=?Flask?(_name__)@app.route('/')def?hello_world():????return?'Hello,?World!'@app.route("/request",?methods=['POST',?'GET'])?def?hellp():????#拿到request參數(shù)?????query?=?request.args?????#El?request?form?????post?=?request.form?????#分別打印拿到的參數(shù)和form?????return?f"query:?{query}"???????????f"post:?{post}"提示下面信息則表示搭建成功。
*?Serving?Flask?app?"hello.py"?*?Environment:?production???WARNING:?Do?not?use?the?development?server?in?a?production?environment.?Use?a?production?WSGI?server?instead.?*?Debug?mode:?off?*?Running?on?http://127.0.0.1:5000/?(Press?CTRL+C?to?quit)CURL 命令發(fā)起 GET/POST 請求
發(fā)起 GET 請求,a、b參數(shù)放入 URL 中發(fā)送,并保存在 get 文件中:
curl?'http://127.0.0.1:5000/request?a=1&b=2'?-V?-S?&>get發(fā)起 POST 請求,a、b參數(shù)以 form-data格式發(fā)送,并保存在post 文件中:
curl?'http://127.0.0.1:5000/request?'?-d?"a=1&b=2"?-V?-S?&>postGET/POST 請求對比
注意:>的右邊為請求內(nèi)容,
GET 請求過程
*???Trying?127.0.0.1...*?TCP_NODELAY?set*?Connected?to?127.0.0.1?(127.0.0.1)?port?5000?(#0)>?GET?/request?a=1&b=2?HTTP/1.1>?Host:?127.0.0.1:5000>?User-Agent:?curl/7.64.1>?Accept:?*/*>*?HTTP?1.0,?assume?close?after?bodyPOST 請求過程
*???Trying?127.0.0.1...*?TCP_NODELAY?set*?Connected?to?127.0.0.1?(127.0.0.1)?port?5000?(#0)>?POST?/request?a=1&b=2?HTTP/1.1>?Host:?127.0.0.1:5000>?User-Agent:?curl/7.64.1>?Accept:?*/*>?Content-Length:?7>?Content-Type:?application/x-www-form-urlencoded>}?[7?bytes?data]*?upload?completely?sent?off:?7?out?of?7?bytes*?HTTP?1.0,?assume?close?after?body對兩個文件進行對比:
從圖中可以清楚看到 GET 請求的 method 為 GET,POST 請求的 method 為 POST,此外,GET 請求沒有 Content-Type 以及 Content-Length 這兩個字段,而請求行中的 URL 帶有 query 參數(shù),是兩種請求都允許的格式。(End)
(文章來源于霍格沃茲測試學院)
總結(jié)
以上是生活随笔為你收集整理的get request uni 参数_接口测试实战| GET/POST 请求区别详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .net 匹配html图片url_后端程
- 下一篇: as f报错 open with_一篇文