When using the RESTful API to request services, you need to fill in the Token field in the HTTP request header for identity authentication.
The method of Token value generation is as follows::
The following is an example code for generating the token field in Java and Python.
String restfulId = "qawsedrftg"; // your secret ID
String restfulSecret = "abcdefghijk"; // your secret key
// generate token
String plainIDSecret = restfulId + ":" + restfulSecret;
String base64IDSecret = new String(Base64.encodeBase64(plainIDSecret.getBytes("UTF-8")));
// Generate the request object and add the token information to the request header
Request request = new Request.Builder()
.addHeader("token", "Base " + base64IDSecret)
...
#!/usr/bin/python3
import requests
import base64
appid = 123456 # your appid
restful_id = 'qawsedrftg' # your secret id
restful_secret = 'abcdefghijk' # your secret key
# http header
headers = {
"content-type": "application/json"
}
# generate token
auth = base64.b64encode(("%s:%s" % (restful_id, restful_secret)).encode('utf-8'))
headers['token'] = 'Base ' + str(auth,'utf-8')
# request
url = "https://ai.jocloud.com/app/123456/v1/image/sync?traceId=bd526528-c0d7-4aa4-803b-f5a3fdc05805"
body = {}
res = requests.post(url, json=body, headers=headers)