跳转至

查询 CRS 设置规则列表

1. 接口描述

接口请求路径:POST /prod-api/waf/wafv3/custody/rules/describeCrsSetupRules

describeCrsSetupRules 用于分页查询指定策略组下的 CRS 基础设置规则(如允许的 HTTP 方法、参数数量上限等),并返回当前配置、默认值与参数元数据。

Token 获取方式见 密钥鉴权

2. 输入参数

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

参数名称 必选 类型 描述
pageNum Integer 当前页数
示例值:1
pageSize Integer 每页显示条目个数
示例值:20
wafId Long 策略组 ID
示例值:22
params Object 扩展参数,一般传 {}

3. 示例

示例1 分页查询 CRS 设置规则

输入示例

{
  "pageNum": 1,
  "pageSize": 20,
  "wafId": 22,
  "params": {}
}

代码调用

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

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

        String requestBody = "{"
                + "\"pageNum\":1,"
                + "\"pageSize\":20,"
                + "\"wafId\":22,"
                + "\"params\":{}"
                + "}";

        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/waf/wafv3/custody/rules/describeCrsSetupRules"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "pageNum": 1,
  "pageSize": 20,
  "wafId": 22,
  "params": {}
}`)

    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))
}

输出示例

{
  "total": 13,
  "rows": [
    {
      "ruleId": 900200,
      "ruleTitle": "允许的请求内容",
      "ruleMessage": "限制请求内容类型\n建议:\n对于RESTful API,添加以下方法:PUT、PATCH、DELETE",
      "defaultVariable": [
        {
          "name": "tx.allowed_methods",
          "values": ["GET", "HEAD", "POST", "OPTIONS"]
        }
      ],
      "variable": [
        {
          "name": "tx.allowed_methods",
          "values": ["GET", "HEAD", "POST", "OPTIONS"]
        }
      ],
      "variableModel": [
        {
          "name": "tx.allowed_methods",
          "type": "arrayOfString",
          "explains": "请求方法",
          "optionalVariables": "[\"GET\",\"HEAD\",\"POST\",\"OPTIONS\",\"PUT\",\"PATCH\",\"DELETE\"]"
        }
      ]
    }
  ],
  "code": 200,
  "msg": "成功"
}

4. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:成功
total Integer 符合条件的总条数。示例值:13
rows Array CRS 设置规则列表
rows[].ruleId Long CRS 设置规则 ID。示例值:900200
rows[].ruleTitle String 规则标题。示例值:允许的请求内容
rows[].ruleMessage String 规则说明与配置建议,可含换行
rows[].defaultVariable Array 平台默认变量配置
rows[].defaultVariable[].name String 变量名。示例值:tx.allowed_methods
rows[].defaultVariable[].values Array of String 默认取值列表。示例值:["GET","HEAD","POST","OPTIONS"]
rows[].variable Array 当前策略组已生效的变量配置;提交修改时使用该结构
rows[].variable[].name String 变量名。示例值:tx.allowed_methods
rows[].variable[].values Array of String 当前取值列表
rows[].variableModel Array 参数元数据,供校验与渲染
rows[].variableModel[].name String variable[].name 对应
rows[].variableModel[].type String 参数类型,支持以下值:
arrayOfString:多选字符串列表
integer:单个整数
示例值:arrayOfString
rows[].variableModel[].explains String 参数中文说明。示例值:请求方法
rows[].variableModel[].optionalVariables String 可选值范围的 JSON 字符串。arrayOfString 时为枚举列表;integer 时一般为 ["最小值","最大值"]

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
查询失败,无效的wafId wafId 不存在或不属于当前账号
wafId不能为空 未传 wafId