跳转至

创建源

1. 接口描述

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

createOrigins 用于为指定海外 ACDN 分发创建源(Origin),可配置协议、端口、SSL、超时、自定义标头及源护盾。账号需具备 acdn:EditDistribution 权限。

Token 获取方式见 密钥鉴权

2. 输入参数

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

参数名称 必选 类型 描述
distributionId Long 分发主键 ID。示例值:34
domainName String 源域名。示例值:origin.example.com
originIdName String 源名称(唯一)。示例值:origin.example.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.2+TLSv1.1)、3(至 TLSv1)、4(至 SSLv3)。示例值:1
originPath String 源路径,附加到源请求的 URL 路径
customHeaders [CustomHeaders] 自定义标头列表
isOriginShield Integer 是否启用源护盾。取值:0(否)、1(是)。示例值:0
originShieldRegion String 源护盾区域。取值:us-east-1us-east-2us-west-2ap-south-1ap-northeast-2ap-southeast-1ap-southeast-2ap-northeast-1eu-central-1eu-west-1eu-west-2sa-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. 输出参数

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

4. 示例

示例1 创建源

输入示例

{
  "connectionAttempts": 3,
  "originReadTimeout": 30,
  "quantity": 1,
  "httpPort": 80,
  "connectionTimeout": 10,
  "domainName": "origin.example.com",
  "distributionId": 34,
  "httpsPort": 443,
  "customHeaders": [],
  "originIdName": "origin.example.com",
  "originPath": "",
  "isOriginShield": 0,
  "originKeepaliveTimeout": 5,
  "protocolPolicy": "http-only"
}

代码调用

请将 {登录域名}token 替换为实际值。

curl -X POST 'https://{登录域名}/prod-api/acdn/originsRest/createOrigins' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "connectionAttempts": 3,
  "originReadTimeout": 30,
  "quantity": 1,
  "httpPort": 80,
  "connectionTimeout": 10,
  "domainName": "origin.example.com",
  "distributionId": 34,
  "httpsPort": 443,
  "customHeaders": [],
  "originIdName": "origin.example.com",
  "originPath": "",
  "isOriginShield": 0,
  "originKeepaliveTimeout": 5,
  "protocolPolicy": "http-only"
}'
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\":\"origin.example.com\","
                + "\"distributionId\":34,"
                + "\"httpsPort\":443,"
                + "\"customHeaders\":[],"
                + "\"originIdName\":\"origin.example.com\","
                + "\"originPath\":\"\","
                + "\"isOriginShield\":0,"
                + "\"originKeepaliveTimeout\":5,"
                + "\"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": "origin.example.com",
  "distributionId": 34,
  "httpsPort": 443,
  "customHeaders": [],
  "originIdName": "origin.example.com",
  "originPath": "",
  "isOriginShield": 0,
  "originKeepaliveTimeout": 5,
  "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
}

5. 错误码

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

6. 数据模型

CustomHeaders

自定义源请求头。

参数名称 必选 类型 描述
headerName String 标头名。示例值:X-Custom-Header
headerValue String 标头值。示例值:demo