创建JS脚本反爬虫规则
功能介绍
创建JS脚本反爬虫规则,在调用此接口创建防护规则前,需要调用更新JS脚本反爬虫规则防护模式(UpdateAnticrawlerRuleType)接口指定防护模式
URI
POST /v1/{project_id}/waf/policy/{policy_id}/anticrawler
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
project_id | 是 | String | 项目ID,对应控制台用户名->我的凭证->项目列表->项目ID |
policy_id | 是 | String | 防护策略id,通过指定防护策略id来指明查询该防护策略下的防护规则,您可以通过调用查询防护策略列表(ListPolicy)获取策略id |
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
enterprise_project_id | 否 | String | 您可以通过调用企业项目管理服务(EPS)的查询企业项目列表接口(ListEnterpriseProject)查询企业项目id |
请求参数
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
X-Auth-Token | 是 | String | 用户Token,通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
Content-Type | 是 | String | 内容类型 |
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
conditions | 是 | Array of AnticrawlerCondition objects | 匹配条件列表 |
name | 是 | String | 规则名称 |
type | 是 | String | JS脚本反爬虫规则类型,指定防护路径:anticrawler_specific_url 排除防护路径:anticrawler_except_url |
priority | 是 | Integer | 执行该规则的优先级,值越小,优先级越高,值相同时,规则创建时间早,优先级越高。取值范围:0到1000。 |
参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
category | 否 | String | 字段类型 |
logic_operation | 否 | String | 条件列表匹配逻辑, 包括:contain、not_contain、equal、not_equal、prefix、not_prefix、suffix、not_suffix、contain_any、not_contain_all、equal_any、not_equal_all、prefix_any、not_prefix_all、suffix_any、not_suffix_all |
contents | 否 | Array of strings | 条件列表逻辑匹配内容。当logic_operation参数不以any或者all结尾时,需要传该参数。 |
value_list_id | 否 | String | 引用表id。当logic_operation参数以any或者all结尾时,需要传该参数。此外,引用表类型要与category类型保持一致。 |
响应参数
状态码:200
参数 | 参数类型 | 描述 |
|---|---|---|
id | String | 规则id |
policyid | String | 策略id |
conditions | Array of AnticrawlerCondition objects | 匹配条件列表 |
name | String | 规则名称 |
type | String | JS脚本反爬虫规则类型,指定防护路径:anticrawler_specific_url 排除防护路径:anticrawler_except_url |
timestamp | Long | 创建规则时间戳 |
status | Integer | 规则状态,0:关闭,1:开启 |
priority | Integer | 执行该规则的优先级,值越小,优先级越高,值相同时,规则创建时间早,优先级越高。取值范围:0到1000。 |
参数 | 参数类型 | 描述 |
|---|---|---|
category | String | 字段类型 |
logic_operation | String | 条件列表匹配逻辑, 包括:contain、not_contain、equal、not_equal、prefix、not_prefix、suffix、not_suffix、contain_any、not_contain_all、equal_any、not_equal_all、prefix_any、not_prefix_all、suffix_any、not_suffix_all |
contents | Array of strings | 条件列表逻辑匹配内容。当logic_operation参数不以any或者all结尾时,需要传该参数。 |
value_list_id | String | 引用表id。当logic_operation参数以any或者all结尾时,需要传该参数。此外,引用表类型要与category类型保持一致。 |
状态码:400
参数 | 参数类型 | 描述 |
|---|---|---|
error_code | String | 错误码 |
error_msg | String | 错误信息 |
状态码:401
参数 | 参数类型 | 描述 |
|---|---|---|
error_code | String | 错误码 |
error_msg | String | 错误信息 |
状态码:500
参数 | 参数类型 | 描述 |
|---|---|---|
error_code | String | 错误码 |
error_msg | String | 错误信息 |
请求示例
在项目id为project_id,防护策略id为policy_id的防护策略下创建JS脚本反爬虫规则,规则名称为“test66”,JS脚本反爬虫规则类型为排除防护路径,匹配条为url包含“/test66”,执行该规则的优先级为50。
POST https://{Endpoint}/v1/{project_id}/waf/policy/{policy_id}/anticrawler?
{
"name" : "test66",
"type" : "anticrawler_except_url",
"conditions" : [ {
"category" : "url",
"logic_operation" : "contain",
"contents" : [ "/test66" ]
} ],
"priority" : 50
} 响应示例
状态码:200
ok
{
"id" : "7e7983bf2c9c41029d642bcbf819346d",
"policyid" : "0681f69f94ac408e9688373e45a61fdb",
"name" : "test66",
"timestamp" : 1678931492172,
"status" : 1,
"type" : "anticrawler_except_url",
"conditions" : [ {
"category" : "url",
"contents" : [ "/test66" ],
"logic_operation" : "contain"
} ],
"priority" : 50
} 状态码
状态码 | 描述 |
|---|---|
200 | ok |
400 | 请求失败 |
401 | token权限不足 |
500 | 服务器内部错误 |
错误码
请参见错误码。

