requests模块发送数据
通过json dumps发送
import requests import json def agent(): """ 执行命令采集硬件信息 将执行的信息发送给API :return: """ info = {'cpu':{'xx':'XXX'},'disk':'xxx'} ret = requests.post( url='http://127.0.0.1:8000/app01/asset/', # data=info # json=info data=json.dumps(info).encode('gbk') ) print(ret) agent()
服务器通过json load接收
from django.shortcuts import render,HttpResponse from django.views.decorators.csrf import csrf_exempt import json @csrf_exempt def asset(request): """ 接收数据 保存数据到数据库 :param request: :return: """ print(request.POST) print(request.body) print(json.loads(request.body.decode('gbk'))) return HttpResponse('ok')
We are down, but not beaten. tested but not defeated.