跳转至

更新域名配置开关

1. 接口描述

接口请求路径:POST /prod-api/cdn/domain/advancedConfigSwitch

advancedConfigSwitch 用于开启或关闭域名某项功能开关(state0 / 1)。请先调用 查询域名配置开关 查看当前状态,再按需修改。

设置白名单、HTTP/3、TLS 等具体参数不在本接口配置,请使用 查询函数配置更新函数(见下方「与更新函数接口的分工」)。查询结果中的超时时间、httpsStatusCode 等数值型配置不能通过本接口修改。

Token 获取方式见 密钥鉴权

2. 输入参数

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

参数名称 必选 类型 描述
domainId Integer 域名 ID
示例值:204
state Integer 开关状态。0:关闭;1:开启。取值与查询接口 data 中对应字段一致
示例值:1
type String 要操作的配置项,与 查询域名配置开关 返回的 data 字段名一致(见下方对照表)
示例值:customRules

3. 示例

示例1 开启自定义规则

输入示例

{
  "type": "customRules",
  "domainId": 204,
  "state": 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 AdvancedConfigSwitchTest {

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

        String requestBody = "{"
                + "\"type\":\"customRules\","
                + "\"domainId\":204,"
                + "\"state\":1"
                + "}";

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpPost httpPost = new HttpPost(url);
            httpPost.setHeader("Authorization", "Bearer " + token);
            httpPost.setHeader("Content-Type", "application/json");
            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/cdn/domain/advancedConfigSwitch"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "type": "customRules",
  "domainId": 204,
  "state": 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
}

4. 输出参数

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

5. type 与查询字段对照

type(本接口传入) 查询接口 data 字段 中文名
httpHeader customHeader HTTP Header
brotli brotli Brotli 压缩
limitRate limitRate 下行限速
cacheRule cacheRule 缓存配置
advanced advanced 指定路径高级
falsify falsify 防篡改
infoReveal infoReveal 防信息泄露
httpIPWhitelist httpIPWhitelist HTTP 层 IP 白名单开关(与下方「设置白名单」无关)
sslsupport sslsupport 证书
bot bot 搜索引擎
http2 http2 HTTP/2
https_301 https_301 强制跳转 HTTPS
webSocket webSocket WebSocket
rangeSource rangeSource Range 回源
filterParameters filterParameters 过滤参数
customRules customRules 自定义规则
ipWhitelist ipWhitelist 设置白名单(仅开关,IP 列表见下方分工说明)
sysRegion sysRegion 地区 / 国家限制
whitelist whitelist 白名单
ruleWhite ruleWhite 规则白名单

注意:HTTP Header 在查询结果中为 customHeader,更新开关时 type 需传 httpHeader,与其余字段不同。

6. 与「更新函数」接口的分工

本接口只改开/关;下列能力的具体配置(设置白名单、HTTP/3、TLS 版本等)请走 更新函数,查询现状请走 查询函数配置

能力 本接口(开关) 更新函数 functionName 说明
设置白名单 不支持(无对应 type IPWhitelist IP 列表仅通过 更新函数 写入
HTTP/3 不支持(无对应 type http3 argNamestatusargValue0(开)或 1(关)
TLS 版本 不支持(无对应 type tls_version argNamestatusargValue01,含义见 查询函数配置

典型流程(设置白名单):

  1. 查询函数配置functionName: "IPWhitelist")→ 获取当前 IP 列表
  2. 更新函数 → 请求体示例:
{
  "domainId": 215,
  "functions": [
    {
      "functionArgs": [
        {
          "argName": "values",
          "argValue": "[\"1.1.1.1\",\"22.2.2.2\"]"
        }
      ],
      "functionName": "IPWhitelist"
    }
  ]
}

7. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
类型错误 type 参数无效
更新失败请确认type是否正确 更新失败,请检查 type 是否正确
CDN10014 域名不存在
CDN10015 域名不属于你