更新高级配置¶
1. 接口描述¶
接口请求路径:POST /prod-api/cdn/layer7/advance/modifyAdvanceRules
modifyAdvanceRules 用于新增或编辑指定域名下的目录高级配置规则。新增时请求体中不写 locationId;编辑时 locationId 必填,取值来自 查询目录高级配置 返回的 data.row[].locationId。
Token 获取方式见 密钥鉴权。
2. 输入参数¶
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| domainId | 是 | Integer / String | 域名 ID 示例值: 215 |
| type | 是 | Integer / String | 规则类型。1:全部;3:文件夹;4:全路径;5:首页示例值: 1 |
| name | 是 | String | 规则内容 示例值: * |
| listClass | 是 | Integer / String | 名单类型。1:白名单;2:黑名单示例值: 1 |
| detectionRobot | 是 | String | 人机识别。on:启用;off:未启用示例值: off |
| whiteBlacklist | 否 | Array of String | IP 名单列表 示例值: ["1.1.1.1"] |
| limitConn | 否 | String | 频率限速 |
| locationId | 否 | Integer | 规则 ID。新增时不写;编辑时必填 示例值: 2676 |
3. 示例¶
示例1 新增高级配置规则¶
输入示例¶
{
"domainId": "215",
"type": "1",
"name": "*",
"whiteBlacklist": ["1.1.1.1"],
"listClass": "1",
"detectionRobot": "off"
}
代码调用¶
请将 {登录域名}、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 ModifyAdvanceRulesTest {
public static void main(String[] args) throws Exception {
String url = "https://{登录域名}/prod-api/cdn/layer7/advance/modifyAdvanceRules";
String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";
String requestBody = "{"
+ "\"domainId\":\"215\","
+ "\"type\":\"1\","
+ "\"name\":\"*\","
+ "\"whiteBlacklist\":[\"1.1.1.1\"],"
+ "\"listClass\":\"1\","
+ "\"detectionRobot\":\"off\""
+ "}";
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/layer7/advance/modifyAdvanceRules"
token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"
requestBody := []byte(`{
"domainId": "215",
"type": "1",
"name": "*",
"whiteBlacklist": ["1.1.1.1"],
"listClass": "1",
"detectionRobot": "off"
}`)
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))
}
输出示例¶
示例2 编辑高级配置规则¶
输入示例¶
{
"domainId": "215",
"type": "1",
"name": "*",
"whiteBlacklist": ["1.1.1.1"],
"listClass": "1",
"detectionRobot": "off",
"locationId": 2676
}
输出示例¶
4. 输出参数¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| code | Integer | 状态码。示例值:200 |
| msg | String | 提示信息。新增时示例值:提交成功;编辑时示例值:更新成功 |
5. 错误码¶
| HTTP 状态码 / 业务提示 | 描述 |
|---|---|
| 200 | 成功 |
| 401 | 未鉴权或 Token 无效 |
| 403 | 无权限 |
| CDN10005 | 规则目录类别错误 |
| CDN10007 | 无效的 IP |
| CDN10014 | 域名不存在 |
| CDN10015 | 域名不属于你 |