views
from django.shortcuts import render, HttpResponse def index(request): print(request.body) #输出结果:b‘username=alex&password=123‘ print(request.POST) #request.POST解析不了JSON格式. return HttpResponse(‘......‘)
request模块模拟发送数据
import requests #请求体格式: # requests.data得到的数据 :b‘username=alex&password=123‘ # requests.POST得到的数据 :<QueryDict: {‘username‘: [‘alex‘], ‘password‘: [‘123‘]}> #以urlencoded格式发送过去的. r1 =requests.post( url ="http://127.0.0.1:8000/index/", data ={"username":"alex","password":123}, ) print(r1.text)
#请求体格式: # requests.data得到的数据 :b‘username=alex&password=123‘ # requests.POST得到的数据 :<QueryDict: {}> #以json字符串格式发送 POST里拿不到数据. r1 =requests.post( url ="http://127.0.0.1:8000/index/", json ={"username":"alex","password":123}, ) print(r1.text)
原文:https://www.cnblogs.com/mengbin0546/p/10417662.html