Basic HTTP Authentication

RESTful API must pass Basic HTTP authentication. You need to get a token and fill in the token field of the HTTP request header. This section introduces how to generate a token and perform HTTP authentication.

Step 1 Get a Certificate ID and Certificate Key

Fill in the certificate ID (restfulId) and certificate key (restfulSecret) to the code.

Certificate ID and certificate key are gotten in the following way:

Log in to Personal Center, and click the account name at the top right to enter the API Certificate page of the drop-down list and get the certificate ID and certificate key.

Note: The certificate ID and certificate key are used for accessing RESTful API only.

Step 2 Generate a Token

Token is an idSecret encoded by the Base64 algorithm. You should use the certificate ID (restfulId) and the certificate key (restfulSecret) to generate a token. In this sample, the token is base64IDSecret.

Following is a sample code:

  • Java
	// Java
// Fill in the certificate ID and certificate key gotten from Personal Center on the portal website.
String plainIDSecret = "restfulId:restfulSecret";
// base64IDSecret is a token value you want.
String base64IDSecret = new String(Base64.encodeBase64(plainIDSecret.getBytes("UTF-8")));

Step 3 HTTP Authentication

Format of the token field in the HTTP request header: Basic base64IDSecret.

Following is a sample code:

  • Java
	// Java
// Send an HTTP request.
Request request = new Request.Builder()
...
// Fill in the gotten token field to the HTTP request header.
.addHeader("token", "Basic base64IDSecret")
...

Was this page helpful?

Helpful Not helpful
Submitted! Your feedback would help us improve the website.
Feedback
Top
<