创建分发(旧版)¶
1. 接口描述¶
接口请求路径:POST /prod-api/acdn/cloudfrontRest/createDistribution
createDistribution(旧版)用于创建海外 ACDN 分发。请求体为扁平字段模型(SaveDistributionVo)。新版创建请见 创建分发(新版)。
前端仍可能调用本路径(/acdn/cloudfrontRest/createDistribution)。
Token 获取方式见 密钥鉴权。
2. 输入参数¶
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| oid | 是 | String | 套餐号 示例值: 202408211234 |
| domainName | 是 | String | 源域名 示例值: ztdemo.com |
| originIdName | 是 | String | 源名称(唯一) 示例值: ztdemo.com |
| protocolPolicy | 是 | String | 源协议策略。取值:http-only:仅 HTTPhttps-only:仅 HTTPSmatch-viewer:匹配查看器示例值: https-only |
| httpPort | 是 | Integer | 源 HTTP 端口,默认 80示例值: 80 |
| httpsPort | 是 | Integer | 源 HTTPS 端口,默认 443示例值: 443 |
| quantity | 是 | Integer | 最低源 SSL 协议。取值:1:TLSv1.22:TLSv1.13:TLSv14:SSLv3示例值: 1 |
| viewerProtocolPolicy | 是 | String | 查看器协议策略。取值:allow-all:HTTP 和 HTTPSredirect-to-https:重定向 HTTP 到 HTTPShttps-only:仅 HTTPS示例值: allow-all |
| allowedMethods | 是 | Integer | 允许的 HTTP 方法。取值:1:GET, HEAD2:GET, HEAD, OPTIONS3:GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE示例值: 1 |
| cachePolicyId | 是 | String | 缓存策略 ID 示例值: 658327ea-f89d-4fab-a63d-7e88639e58f6 |
| priceClass | 是 | String | 价格级别。取值:PriceClass_All:使用所有边缘站点(最佳性能)PriceClass_100:仅北美洲和欧洲PriceClass_200:北美洲、欧洲、亚洲、中东和非洲示例值: PriceClass_All |
| isLogging | 是 | Integer | 是否开启标准日志。取值:0:关闭1:开启示例值: 1 |
| isCookie | 是 | Integer | Cookie 是否写入日志。取值:0:关闭1:开启示例值: 0 |
| isIpv6Enabled | 是 | Integer | 是否启用 IPv6。取值:0:关闭1:开启示例值: 1 |
| isCompress | 否 | Integer | 是否自动压缩。取值:0:否1:是示例值: 1 |
| isOptions | 否 | Boolean | 是否缓存 OPTIONS(当 allowedMethods 为 2 或 3 时) |
| isOriginShield | 否 | Integer | 是否启用源护盾。取值:0:否1:是 |
| originShieldRegion | 否 | String | 源护盾区域。示例值:us-east-1 |
| originPath | 否 | String | 源路径 |
| connectionAttempts | 否 | Integer | 连接尝试次数,范围 1–3,默认 3 |
| connectionTimeout | 否 | Integer | 连接超时(秒),范围 1–10,默认 10 |
| originReadTimeout | 否 | Integer | 响应超时(秒),范围 1–60,默认 30 |
| originKeepaliveTimeout | 否 | Integer | 保持连接超时(秒),范围 1–60,默认 5 |
| customHeaders | 否 | Array | 自定义源请求头,见 CustomHeadersVo |
| originRequestPolicyId | 否 | String | 源请求策略 ID |
| responseHeadersPolicyId | 否 | String | 响应头策略 ID |
| isSmoothStreaming | 否 | Integer | Smooth Streaming。取值:0:否1:是 |
| aliases | 否 | Array | 备用域名(CNAME),元素见 ValueVo |
| sslCertificateId | 否 | String | SSL 证书 ID |
| protocolVersionType | 否 | String | 安全策略。取值:TLSv1.2_2021TLSv1.2_2019TLSv1.2_2018TLSv1.1_2016TLSv1_2016TLSv1 |
| isHttpVersion | 否 | Boolean | 是否支持 HTTP/2 |
| defaultRootObject | 否 | String | 默认根对象 |
| webACLId | 否 | String | WAF Web ACL ID |
| comment | 否 | String | 备注 |
| trusted | 否 | Object | 受限访问配置,见 TrustedVo |
| isTrusted | 否 | Integer | 是否启用受限访问 |
3. 示例¶
示例1 创建分发(旧版)¶
输入示例¶
{
"allowedMethods": 1,
"domainName": "ztdemo.com",
"httpPort": 80,
"httpsPort": 443,
"isCompress": 1,
"isIpv6Enabled": 1,
"isLogging": 1,
"isOriginShield": 0,
"isSmoothStreaming": 0,
"oid": "202408211234",
"originIdName": "ztdemo.com",
"quantity": 1,
"viewerProtocolPolicy": "allow-all",
"comment": "",
"connectionTimeout": 10,
"connectionAttempts": 3,
"originKeepaliveTimeout": 5,
"originReadTimeout": 30,
"isCookie": 0,
"protocolPolicy": "https-only",
"priceClass": "PriceClass_All",
"cachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"customHeaders": [
{
"headerName": "demo",
"headerValue": "1"
}
]
}
代码调用¶
请将 {登录域名}、token 替换为实际值。
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class CreateDistributionOldTest {
public static void main(String[] args) throws Exception {
String url = "https://{登录域名}/prod-api/acdn/cloudfrontRest/createDistribution";
String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";
String requestBody = "{{"
+ "\"allowedMethods\":1,"
+ "\"domainName\":\"ztdemo.com\","
+ "\"httpPort\":80,"
+ "\"httpsPort\":443,"
+ "\"isCompress\":1,"
+ "\"isIpv6Enabled\":1,"
+ "\"isLogging\":1,"
+ "\"isCookie\":0,"
+ "\"oid\":\"202408211234\","
+ "\"originIdName\":\"ztdemo.com\","
+ "\"quantity\":1,"
+ "\"viewerProtocolPolicy\":\"allow-all\","
+ "\"protocolPolicy\":\"https-only\","
+ "\"priceClass\":\"PriceClass_All\","
+ "\"cachePolicyId\":\"658327ea-f89d-4fab-a63d-7e88639e58f6\""
+ "}}";
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Authorization", "Bearer " + token);
httpPost.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
int statusCode = response.getStatusLine().getStatusCode();
String body = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println("Status Code: " + statusCode);
System.out.println("Body: " + body);
}
}
}
}
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
url := "https://{登录域名}/prod-api/acdn/cloudfrontRest/createDistribution"
token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"
requestBody := []byte(`{{
"allowedMethods": 1,
"domainName": "ztdemo.com",
"httpPort": 80,
"httpsPort": 443,
"isCompress": 1,
"isIpv6Enabled": 1,
"isLogging": 1,
"isCookie": 0,
"oid": "202408211234",
"originIdName": "ztdemo.com",
"quantity": 1,
"viewerProtocolPolicy": "allow-all",
"protocolPolicy": "https-only",
"priceClass": "PriceClass_All",
"cachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6"
}}`)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(requestBody))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println("Body:", string(body))
}
输出示例¶
4. 输出参数¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| code | Integer | 状态码。示例值:200 |
| msg | String | 提示信息。示例值:添加成功 |
5. 错误码¶
| HTTP 状态码 / 业务提示 | 描述 |
|---|---|
| 200 | 成功 |
| 401 | 未鉴权或 Token 无效 |
| 403 | 无权限 |
| 源域名不能为空! | 未传入 domainName |
| 协议类型错误! | protocolPolicy 非法 |
| 套餐不能为空! / 套餐不存在。 | oid 无效 |
| 该套餐可使用分发数量不足 | 超出套餐分发配额 |
| HTTP端口不能为空! / HTTPS端口不能为空! | 端口缺失 |
| 最低源 SSL 协议不能为空! | quantity 非法 |
| 源名称不能为空! | 未传入 originIdName |
| 查看器协议类型不能为空! | viewerProtocolPolicy 非法 |
| 价格级别不能为空! | priceClass 非法 |
| 缓存策略不能为空! | 未传入 cachePolicyId |
| 请检查标准日志!请检查 | isLogging / isCookie 缺失 |
| 允许的协议类型有误!请检查! | allowedMethods 缺失 |
| ipv6有误!请检查! | isIpv6Enabled 缺失 |
| 添加失败 | 后端创建失败 |
6. 数据模型¶
CustomHeadersVo¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| headerName | String | 标头名 |
| headerValue | String | 标头值 |
ValueVo¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| value | String | CNAME 域名 |
TrustedVo¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| trustedType | Integer | 受信类型 |
| keyGroupsId | Long | 密钥组 ID |
| awsAccount | Array | AWS 账号列表 |