修改自定义响应页面¶
1. 接口描述¶
接口请求路径:POST /prod-api/acdn/cloudfrontRest/updateCustomErrorPage
updateCustomErrorPage 用于创建或修改海外 ACDN 分发的自定义错误响应页面。若 oldErrorCode 已存在则更新该条,否则新增。账号需具备 acdn:EditDistribution 权限。
Token 获取方式见 密钥鉴权。
2. 输入参数¶
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| distributionId | 是 | Long | 分发主键 ID。示例值:38 |
| oldErrorCode | 是 | Integer | 修改前的 HTTP 错误代码;新建时可与 errorCode 相同。示例值:400 |
| errorCode | 是 | Integer | HTTP 错误代码。取值:400(错误请求)、403(禁止)、404(找不到)、405(不允许的方法)、414(请求 URI 过长)、416(范围不满意)、500(内部服务器错误)、501(未实现)、502(无效网关)、503(服务不可用)、504(网关超时)。示例值:400 |
| responseCode | 否 | String | HTTP 响应代码。取值:200、400、403、404、405、414、416、500、501、502、503、504。示例值:200 |
| responsePagePath | 否 | String | 响应页面路径。示例值:/custom-error.html |
| errorCachingMinTTL | 是 | Long | 错误缓存最小 TTL(秒)。示例值:10 |
3. 输出参数¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| code | Integer | 状态码。示例值:200 |
| msg | String | 提示信息。示例值:更新成功 |
4. 示例¶
示例1 修改自定义错误响应¶
输入示例¶
{
"errorCode": 400,
"responseCode": "200",
"responsePagePath": "/custom-error.html",
"oldErrorCode": 400,
"distributionId": 38,
"errorCachingMinTTL": 10
}
代码调用¶
请将 {登录域名}、token 替换为实际值。
curl -X POST 'https://{登录域名}/prod-api/acdn/cloudfrontRest/updateCustomErrorPage' \
-H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"errorCode": 400,
"responseCode": "200",
"responsePagePath": "/custom-error.html",
"oldErrorCode": 400,
"distributionId": 38,
"errorCachingMinTTL": 10
}'
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 UpdateCustomErrorPageTest {
public static void main(String[] args) throws Exception {
String url = "https://{登录域名}/prod-api/acdn/cloudfrontRest/updateCustomErrorPage";
String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";
String requestBody = "{"
+ "\"errorCode\":400,"
+ "\"responseCode\":\"200\","
+ "\"responsePagePath\":\"/custom-error.html\","
+ "\"oldErrorCode\":400,"
+ "\"distributionId\":38,"
+ "\"errorCachingMinTTL\":10"
+ "}";
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/acdn/cloudfrontRest/updateCustomErrorPage"
token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"
requestBody := []byte(`{
"errorCode": 400,
"responseCode": "200",
"responsePagePath": "/custom-error.html",
"oldErrorCode": 400,
"distributionId": 38,
"errorCachingMinTTL": 10
}`)
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))
}
输出示例¶
5. 错误码¶
| HTTP 状态码 / 业务提示 | 描述 |
|---|---|
| 200 | 成功 |
| 401 | 未鉴权或 Token 无效 |
| 403 | 无权限 |
| id不能为空! | 未传入 distributionId |
| oldErrorCode can't null! | 未传入 oldErrorCode |
| 无有效id | 分发不存在或不属于当前账号 |
| 更新失败 | 更新未成功 |