所以在查看了文档之后,这里是我如何设置GET和POST请求的。我首先要对我们的身份验证做一个POST来取回一个承载令牌。一旦我有了那个令牌,我就创建了一个局部变量来存储令牌。然后提出任何我想要的GET请求,然后把令牌传了进去。下面是看起来很明显你会填写你自己的用户名,密码,网址和令牌,但是你明白了。在
发布请求-获取我的承载令牌#import requests library for making REST calls
import requests
import json
#specify url
url = 'YOUR URL GOES HERE'
#Create payload that will be passed to API for authentication
payload = {
#This will be the data that you need to POST to the REST API.
In my example, in order to get back a web token, I just needed username and password.
"username": "USERNAME",
"password": "PASSWORD"
}
#Fill in headers
headers = {'content-type': 'application/json'}
#Call REST API
response = requests.post(url, data=json.dumps(payload), headers=headers)
#Print Response
print(response.text)
获取请求-从上面使用承载令牌时取回数据
^{pr2}$