![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import requests # requests.get(url='http://127.0.0.1:8000/api/asset/?K1=123') # requests.get(url='http://127.0.0.1:8000/api/asset/',params={'k1':'v1'}) # # url表示往哪里发送数据,params表示传输的参数是什么 requests.post(url='http://127.0.0.1:8000/api/asset/')#触发了csrf的认证
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import requests # requests.get(url='http://127.0.0.1:8000/api/asset/?K1=123') # requests.get(url='http://127.0.0.1:8000/api/asset/',params={'k1':'v1'}) # # url表示往哪里发送数据,params表示传输的参数是什么 requests.post(url='http://127.0.0.1:8000/api/asset/', params={'k1':'v1','k2':'v2'},#GET形式传输 data={'username':'pandaboy','password':'5555'})#POST形式传输 #触发了csrf的认证,params触发的是get方式,data触发的是POST形式
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
host_data = { 'status':True, 'data':{ 'hostname':'c1.com', 'disk':{'status':True,'data':'XXX'}, 'mem':{'status':True,'data':'XXX'}, 'nic': {'status': True, 'data': 'XXX'}, } } requests.post(url='http://127.0.0.1:8000/api/asset/', json=host_data, # params={'k1':'v1','k2':'v2'},#GET形式传输 # data={'username':'pandaboy','password':'5555'}, # header = {'a':'123'},#请求头传递数据 )#POST形式传输 #触发了csrf的认证,params触发的是get方式,data触发的是POST形式
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
from django.shortcuts import render,HttpResponse from django.views.decorators.csrf import csrf_exempt,csrf_protect # Create your views here. @csrf_exempt#这个装饰器就是取消CSRF的验证 def asset(request): # print(request.method) # print(request.POST) # print(request.GET) if request.method == 'POST': import json host_info = json.loads(str(request.body,encoding='UTF-8')) print(host_info) return HttpResponse('....') # Post发送请求是放在请求体中的
以下内容已经有bug了,request.META中是没有[HTTP_AUTHKEY]这个字典的
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
from django.shortcuts import render,HttpResponse from django.views.decorators.csrf import csrf_exempt,csrf_protect # Create your views here. ck = 'asd7asd1345ad' @csrf_exempt#这个装饰器就是取消CSRF的验证 def asset(request): # print(request.method) # print(request.POST) # print(request.GET) auth_key = request.META['HTTP_AUTHKEY']#没有HTTP_AUTHKEY这个字典 print(auth_key) if auth_key!=ck: return HttpResponse('授权失败') if request.method == 'POST': import json host_info = json.loads(str(request.body,encoding='UTF-8')) print(host_info) return HttpResponse('....') # Post发送请求是放在请求体中的
加密策略:
1.设置固定"盐"
2.设置时间戳
3.进行md5加密
4.同时发送"盐"+时间戳给服务端