跳转至

更新转发规则

1. 接口描述

接口请求路径:POST /prod-api/cdn/layer4/rules/updateRule

updateRule 用于更新指定 TCP/UDP(四层)转发规则。请求体为单条规则对象,ruleId 必填。

Token 获取方式见 密钥鉴权

2. 输入参数

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

参数名称 必选 类型 描述
ruleId Long 规则 ID
示例值:81
originAddress String 源站地址,多个地址用英文分号 ; 分隔
示例值:12.12.12.2
protocolType String 转发协议,支持以下值:
tcp:TCP
udp:UDP
示例值:udp
types String 会话保持,支持以下值:
off:否
on:是
示例值:off
limitConn Integer 频率限速(连接数限制)
listenPort String 转发端口(边缘监听端口)
示例值:1333
hyPort String 源站端口
示例值:133
remark String 备注
proxyProtocol String Proxy Protocol,支持以下值:
off:禁用
on:启用
示例值:off
node String 实例标识,如 line_1
示例值:line_1

3. 示例

示例1 更新转发规则

输入示例

{
  "ruleId": 81,
  "types": "off",
  "protocolType": "udp",
  "node": "line_1",
  "proxyProtocol": "off",
  "hyPort": "133",
  "listenPort": "1333",
  "originAddress": "12.12.12.2"
}

代码调用

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

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

        String requestBody = "{"
                + "\"ruleId\":81,"
                + "\"types\":\"off\","
                + "\"protocolType\":\"udp\","
                + "\"node\":\"line_1\","
                + "\"proxyProtocol\":\"off\","
                + "\"hyPort\":\"133\","
                + "\"listenPort\":\"1333\","
                + "\"originAddress\":\"12.12.12.2\""
                + "}";

        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/cdn/layer4/rules/updateRule"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "ruleId": 81,
  "types": "off",
  "protocolType": "udp",
  "node": "line_1",
  "proxyProtocol": "off",
  "hyPort": "133",
  "listenPort": "1333",
  "originAddress": "12.12.12.2"
}`)

    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 无权限
操作失败,转发规则不存在 规则不存在或不属于当前账号
操作失败,套餐信息不存在 规则关联套餐不存在
套餐信息不存,请刷新后重试 套餐不存在或不属于四层套餐
套餐已关闭,无法继续更新转发规则 套餐状态为关闭
套餐已过期,无法继续更新转发规则 套餐已过期
套餐已关闭,无法继续添加转发规则 套餐状态为关闭(业务校验)
套餐已过期,无法继续添加转发规则 套餐已过期(业务校验)
更新失败 更新未成功