跳转至

更新托管规则状态

1. 接口描述

接口请求路径:GET /prod-api/waf/wafv3/custody/rules/changeCustodyRuleStatus

changeCustodyRuleStatus 用于单独切换某条托管检测规则的启用模式,不修改规则参数。ruleId 来自 查询托管规则明细列表

Token 获取方式见 密钥鉴权

2. 输入参数

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

参数名称 必选 类型 描述
wafId Long Query 参数。策略组 ID
示例值:22
ruleId Long Query 参数。托管规则 ID
示例值:1001
status String Query 参数。目标状态,支持以下值:
ON:启用
OFF:关闭
DEFAULT:使用默认/推荐状态
示例值:ON

3. 示例

示例1 启用托管规则

输入示例

GET /prod-api/waf/wafv3/custody/rules/changeCustodyRuleStatus?wafId=22&ruleId=1001&status=ON

代码调用

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

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class ChangeCustodyRuleStatusTest {

    public static void main(String[] args) throws Exception {
        String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";

        URIBuilder uriBuilder = new URIBuilder(
                "https://{登录域名}/prod-api/waf/wafv3/custody/rules/changeCustodyRuleStatus");
        uriBuilder.addParameter("wafId", "22");
        uriBuilder.addParameter("ruleId", "1001");
        uriBuilder.addParameter("status", "ON");

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpGet httpGet = new HttpGet(uriBuilder.build());
            httpGet.setHeader("Authorization", "Bearer " + token);

            try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
                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 (
    "fmt"
    "io"
    "net/http"
    "net/url"
)

func main() {
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    q := url.Values{}
    q.Set("wafId", "22")
    q.Set("ruleId", "1001")
    q.Set("status", "ON")
    urlStr := "https://{登录域名}/prod-api/waf/wafv3/custody/rules/changeCustodyRuleStatus?" + q.Encode()

    req, err := http.NewRequest(http.MethodGet, urlStr, nil)
    if err != nil {
        panic(err)
    }
    req.Header.Set("Authorization", "Bearer "+token)

    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,
  "data": 1001
}

4. 输出参数

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

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
状态[status]只能为DEFAULT、OFF、ON status 取值非法
失败,无效的ruleId ruleId 不存在