跳转至

创建源

1. 接口描述

接口请求路径:POST /prod-api/acdn/originsRest/createOrigins

createOrigins 用于为指定海外 ACDN 分发创建源(Origin),可配置协议、端口、SSL、超时、自定义标头及源护盾。

Token 获取方式见 密钥鉴权

2. 输入参数

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

参数名称 必选 类型 描述
distributionId Long 分发主键 ID
示例值:34
domainName String 源域名
示例值:ztta.com
originIdName String 源名称(唯一)
示例值:ztta.com
protocolPolicy String 协议策略,支持以下值:
http-only:仅 HTTP
https-only:仅 HTTPS
match-viewer:匹配查看器
示例值:http-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
originPath String 源路径,附加到源请求的 URL 路径
customHeaders Array 自定义标头列表
customHeaders.headerName String 标头名
customHeaders.headerValue String 标头值
isOriginShield Integer 是否启用源护盾,支持以下值:
0:否
1:是
示例值:1
originShieldRegion String 源护盾 AWS 区域,支持以下值:
us-east-1:美国东部(弗吉尼亚北部)
us-east-2:美国东部(俄亥俄)
us-west-2:美国西部(俄勒冈)
ap-south-1:亚太地区(孟买)
ap-northeast-2:亚太地区(首尔)
ap-southeast-1:亚太地区(新加坡)
ap-southeast-2:亚太地区(悉尼)
ap-northeast-1:亚太地区(东京)
eu-central-1:欧洲(法兰克福)
eu-west-1:欧洲(爱尔兰)
eu-west-2:欧洲(伦敦)
sa-east-1:南美洲(圣保罗)
示例值:us-east-1
connectionAttempts Integer 连接尝试次数(1–3,默认 3)
示例值:3
connectionTimeout Integer 连接超时(秒,1–10,默认 10)
示例值:10
originReadTimeout Integer 响应超时(秒,1–60,默认 30)
示例值:30
originKeepaliveTimeout Integer 保持连接超时(秒,1–60,默认 5)
示例值:5

3. 示例

示例1 创建源

输入示例

{
  "connectionAttempts": 3,
  "originReadTimeout": 30,
  "quantity": 1,
  "httpPort": 80,
  "connectionTimeout": 10,
  "domainName": "ztta.com",
  "distributionId": 34,
  "httpsPort": 443,
  "customHeaders": [
    {
      "headerValue": "",
      "headerName": ""
    }
  ],
  "originIdName": "ztta.com",
  "originPath": "",
  "isOriginShield": 1,
  "originKeepaliveTimeout": 5,
  "originShieldRegion": "us-east-1",
  "protocolPolicy": "http-only"
}

代码调用

请将 {登录域名}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 CreateOriginsTest {

    public static void main(String[] args) throws Exception {
        String url = "https://{登录域名}/prod-api/acdn/originsRest/createOrigins";
        String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";

        String requestBody = "{"
                + "\"connectionAttempts\":3,"
                + "\"originReadTimeout\":30,"
                + "\"quantity\":1,"
                + "\"httpPort\":80,"
                + "\"connectionTimeout\":10,"
                + "\"domainName\":\"ztta.com\","
                + "\"distributionId\":34,"
                + "\"httpsPort\":443,"
                + "\"customHeaders\":[{\"headerValue\":\"\",\"headerName\":\"\"}],"
                + "\"originIdName\":\"ztta.com\","
                + "\"originPath\":\"\","
                + "\"isOriginShield\":1,"
                + "\"originKeepaliveTimeout\":5,"
                + "\"originShieldRegion\":\"us-east-1\","
                + "\"protocolPolicy\":\"http-only\""
                + "}";

        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/originsRest/createOrigins"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "connectionAttempts": 3,
  "originReadTimeout": 30,
  "quantity": 1,
  "httpPort": 80,
  "connectionTimeout": 10,
  "domainName": "ztta.com",
  "distributionId": 34,
  "httpsPort": 443,
  "customHeaders": [
    {
      "headerValue": "",
      "headerName": ""
    }
  ],
  "originIdName": "ztta.com",
  "originPath": "",
  "isOriginShield": 1,
  "originKeepaliveTimeout": 5,
  "originShieldRegion": "us-east-1",
  "protocolPolicy": "http-only"
}`)

    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
}

4. 输出参数

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

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
创建失败 创建未成功