API
2021-05-09 03:29
标签:.text 客户端 int blog html ext ade nbsp htm API 1.在请求头中加入key server 给客户端发一个key client (key) 服务端在client请求中看是否有key,如果有就是正常客户端没有就是非正常客户端 API 标签:.text 客户端 int blog html ext ade nbsp htm 原文地址:http://www.cnblogs.com/morgana/p/7618306.htmlclient.py
import requests
key="qwrwertyuiop"
response = requests.get("http://127.0.0.1:8000/api/test.html",header={‘auth-api‘:key})
print(response.text)
server.py
from django.http import HttpResponse
key="qwrwertyuiop"
def test(request):
client_key=request.META.get("HTTP_AUTH_API")
if client_key == key:
return HttpResponse("you get me")
else:
return HttpResponse("no")