跳转至

创建分发(旧版)

1. 接口描述

接口请求路径:POST /prod-api/acdn/cloudfrontRest/createDistribution

createDistribution(旧版)用于创建海外 ACDN 分发。请求体为扁平字段模型。新版创建请见 创建分发(新版)。账号需具备 acdn:CreateDistribution 权限。

Token 获取方式见 密钥鉴权

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数

参数名称 必选 类型 描述
oid String 套餐号。示例值:202408211234
domainName String 源域名。示例值:ztdemo.com
originIdName String 源名称(唯一)。示例值:ztdemo.com
protocolPolicy String 源协议策略。取值:http-only(仅 HTTP)、https-only(仅 HTTPS)、match-viewer(匹配查看器)。示例值:https-only
httpPort Integer 源 HTTP 端口。默认值:80。示例值:80
httpsPort Integer 源 HTTPS 端口。默认值:443。示例值:443
quantity Integer 最低源 SSL 协议。取值:1(TLSv1.2)、2(TLSv1.1)、3(TLSv1)、4(SSLv3)。示例值:1
viewerProtocolPolicy String 查看器协议策略。取值:allow-all(HTTP 和 HTTPS)、redirect-to-https(重定向 HTTP 到 HTTPS)、https-only(仅 HTTPS)。示例值:allow-all
allowedMethods Integer 允许的 HTTP 方法。取值:1(GET, HEAD)、2(GET, HEAD, OPTIONS)、3(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(当 allowedMethods23 时)
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 [CustomHeaders] 自定义源请求头
originRequestPolicyId String 源请求策略 ID
responseHeadersPolicyId String 响应头策略 ID
isSmoothStreaming Integer Smooth Streaming。取值:0(否)、1(是)
aliases [Value] 备用域名(CNAME)
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 Trusted 受限访问配置
isTrusted Integer 是否启用受限访问

3. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:添加成功

4. 示例

示例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 替换为实际值。

curl -X POST 'https://{登录域名}/prod-api/acdn/cloudfrontRest/createDistribution' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "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",
  "customHeaders": [
    {
      "headerName": "demo",
      "headerValue": "1"
    }
  ]
}'
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 CreateDistributionTest {

    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\","
                + "\"customHeaders\":[{\"headerName\":\"demo\",\"headerValue\":\"1\"}]"
                + "}";

        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",
  "customHeaders": [
    {
      "headerName": "demo",
      "headerValue": "1"
    }
  ]
}`)

    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))
}

输出示例

{
  "msg": "添加成功",
  "code": 200
}

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
源域名不能为空! 未传入 domainName
协议类型错误! protocolPolicy 非法
套餐不能为空! 未传入 oid
套餐不存在。 oid 不属于当前账号或订单类型不匹配
该套餐可使用分发数量不足 超出套餐分发配额
HTTP端口不能为空! 未传入 httpPort
HTTPS端口不能为空! 未传入 httpsPort
最低源 SSL 协议不能为空! quantity 非法或缺失
源名称不能为空! 未传入 originIdName
查看器协议类型不能为空! viewerProtocolPolicy 非法或缺失
价格级别不能为空! priceClass 非法或缺失
缓存策略不能为空! 未传入 cachePolicyId
请检查标准日志!请检查 isLogging / isCookie 缺失
允许的协议类型有误!请检查! allowedMethods 缺失
ipv6有误!请检查! isIpv6Enabled 缺失
添加失败 后端创建失败

6. 数据模型

CustomHeaders

自定义源请求头。

参数名称 必选 类型 描述
headerName String 标头名
headerValue String 标头值

Value

备用域名(CNAME)元素。

参数名称 必选 类型 描述
value String CNAME 域名

Trusted

受限访问配置。

参数名称 必选 类型 描述
trustedType Integer 受信类型
keyGroupsId Long 密钥组 ID
awsAccount [Value] AWS 账号列表