python之POST介面與GET介面開發簡單例子

2021-08-20 01:36:15 字數 1071 閱讀 6174

我所使用的是python3.6.5,django版本是2.0.5

get請求

#建立引數字典

result = {}

username = request.get.get('username')

telnum = request.get.get('telnum')

date = request.get.get('date')

result['username'] = username

result['telnum'] = telnum

result['date'] = date

#把字典轉換成json

result = json.dumps(result)

else:

#返回login頁面

return render_to_response('login.html')

(2)urls.py

from django.contrib import admin

from django.urls import path

from web.views import login

urlpatterns = [

path('admin/', admin.site.urls),

path('login/',login),#對映路徑

](3)login.html

(4)輸入http://localhost:8000/login/?username=oasd&telnum=123132&date=20180516頁面返回引數字典

post請求只需把view.py中的get替換成post,但要注意引數的個數

python介面測試 post請求(二)

使用post請求登陸小極客網。1 獲取登陸介面,及使用者名稱和密碼引數 進入小極客網,先註冊個賬戶,修改使用者名稱和密碼,然後點選登陸,開啟debug除錯 進入到network下 輸入使用者名稱和密碼,點選登陸 如下圖 獲得登陸介面 使用者名稱變數為 username 密碼變數為 password ...

python介面自動化 post請求2

一 headers 1.以禪道登入為例,模擬登陸,這裡需新增請求頭headers,可以用fiddler抓包 2.將請求頭寫成字典格式 h 二 禪道登入實操 coding utf 8 import requests host def login s,username,psw url host zent...

Python指令碼完成post介面測試的例項

乙個程式設計客棧post型別的介面怎麼編寫指令碼實現 1 開啟網頁,在fiddler上獲取到介面的url 2 用python的requests庫實現 import requests new url params payload results requests程式設計客棧.post new url,...