一、应用1发送post请求
def login(url, data): response = requests.post(url, json=data) if response.status_code == 200: result = response.json() print(result) return result else: return None try: url = "http://127.0.0.1:81/slwloginpro/" data = {'username': username, 'password': password} result = slwlogin(url, data) if result: print("登录或注册成功") else: print("登录或注册成功") except: print("用户登入异常")
二、应用2服务端接收数据
@csrf_exempt def login(request): print(request.method) if request.method=='POST': raw_data = request.body.decode("utf-8") json_data = json.loads(raw_data) name = json_data['username'] pwd = json_data['password'] print(json_data) print("name:"+name) print("pwd:"+pwd) slwmsg={'loginflag':'登录success'} slwmsg_json = json.dumps(slwmsg) return HttpResponse(slwmsg_json)
标签:slwmsg,url,Django,json,result,print,POST,data,服务端 From: https://www.cnblogs.com/songwmeta/p/17962804