Urlencoded sending a JSON string

您所在的位置:网站首页 form-encoded Urlencoded sending a JSON string

Urlencoded sending a JSON string

2023-05-19 03:33| 来源: 网络整理| 查看: 265

I have an API that has been set up on the server side and the unit side, I have the below code in python to communicate with the API. I am now writing this for the Arduino IDE.

This code successfully communicates with the API to get the token.

How is this code sending a JSON string ‘auth_info’ while the header reads x-www-form-urlencoded.

Even a half explanation of the following would be really appreciated.

PYTHON CODE STARTS

def get_user_auth_token(): global token purl = host+'/api/oauth/token' head = {'Content-Type' : 'application/x-www-form-urlencoded'} auth_info = {'client_id' : "unit:"+api_params.id, 'grant_type' : 'client_credentials', 'client_secret' : api_params.secret, 'scope' : 'unit', } # print(purl) # print(auth_info) # print(head) r = requests.post(purl, auth_info, head) response=json.loads(r.text) token = response['access_token']

PYTHON CODE ENDS



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3