Native HTTPS call
Fraud Detection supports native HTTPS calls for scenarios where an SDK is not suitable, such as size-constrained mobile apps or fixed library dependencies.
When to use native HTTPS calls
With native HTTPS calls, you implement the signature process yourself and assemble the request URL, body, headers, and parameters.
Native HTTPS calls are recommended only in the following scenarios. In all other cases, use an SDK call instead.
Client size — You use the service directly in an app and have strict requirements on client size.
Dependency version — You must use a specific version of a dependent library package that cannot be easily upgraded.
Prerequisites
An AccessKey pair issued by Alibaba Cloud. Create and manage AccessKey pairs on the Alibaba Cloud website.
Endpoints and request attributes
The following table lists the public endpoint and the VPC endpoint of Fraud Detection in each region.
| Region | Region ID | Public endpoint | VPC endpoint |
| China (Shanghai) | cn-shanghai | https://saf.cn-shanghai.aliyuncs.com | https://saf-vpc.cn-shanghai.aliyuncs.com |
| China (Beijing) | cn-beijing | https://saf.cn-beijing.aliyuncs.com | https://saf-vpc.cn-beijing.aliyuncs.com |
| China (Hangzhou) | cn-hangzhou | https://saf.cn-hangzhou.aliyuncs.com | https://saf-vpc.cn-hangzhou.aliyuncs.com |
| China (Shenzhen) | cn-shenzhen | https://saf.cn-shenzhen.aliyuncs.com | https://saf-vpc.cn-shenzhen.aliyuncs.com |
| China (Zhangjiakou) | cn-zhangjiakou | https://saf.cn-zhangjiakou.aliyuncs.com | https://saf-vpc.cn-zhangjiakou.aliyuncs.com |
The following table lists the fixed attributes of a native HTTPS request to Fraud Detection.
| Parameter | Value |
| Protocol | HTTPS |
| Method | POST |
| Action | ExecuteRequest |
Sign a request
Fraud Detection authenticates every request, so each request must carry a Signature parameter.
Authentication is based on an AccessKey pair. The AccessKey ID identifies the requester. The AccessKey Secret is the key that produces the signature and lets the server verify the request, so keep it confidential.
To sign a request, follow these steps:
Construct a canonicalized query string from the request parameters.
Sort all request parameters in lexicographical order by parameter name. These parameters include all common request parameters and any operation-specific parameters. The canonicalized query string in the request must not contain the
Signatureparameter itself.URL-encode the parameter names and values by using the UTF-8 character set. The URL encoding rules are as follows:
Do not encode uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), hyphens (-), underscores (_), periods (.), or tildes (~).
Encode other characters into the
%XYformat, where XY is the two-digit hexadecimal representation of the character's ASCII code. For example, a double quotation mark (") is encoded as%22.Encode extended UTF-8 characters into the
%XY%ZA...format.Encode a space as
%20instead of a plus sign (+).
NoteMost standard libraries for URL encoding, such as
java.net.URLEncoderin Java, follow theapplication/x-www-form-urlencodedMIME type. You can use these libraries for encoding. After encoding, replace the plus sign (+) with%20, the asterisk (*) with%2A, and%7Eback to a tilde (~) to produce a string that conforms to the preceding rules.Concatenate the encoded parameter names and values with an equal sign (
=).Concatenate the resulting strings in lexicographical order by parameter name with ampersands (
&) to obtain the canonicalized query string.
Use the canonicalized query string from the previous step to construct the string-to-sign as follows:
StringToSign = HTTPMethod + "&" + percentEncode("/") + "&" + percentEncode(CanonicalizedQueryString)HTTPMethodis the HTTP method used for the request, such asPOST.percentEncode("/")is the encoded value of the forward slash (/), which is%2F.percentEncode(CanonicalizedQueryString)is the canonicalized query string from step 1, encoded according to the URL encoding rules in step 1.b.
Calculate the HMAC value of the string-to-sign as defined in RFC 2104. Use the
SHA1hash algorithm and a key that consists of your AccessKey Secret followed by an ampersand (&, ASCII 38).Base64-encode the resulting HMAC value. The result is the signature (
Signature).Add the signature to the request as the
Signatureparameter. The request is now signed.ImportantWhen you submit the signature to the Fraud Detection server as a request parameter, URL-encode it as specified in RFC 3986, like every other parameter.