修改源¶
1. 接口描述¶
接口请求路径:POST /prod-api/acdn/originsRest/updateOrigins
updateOrigins 用于修改指定海外 ACDN 分发下的源配置。修改时需传入原源名称 oldOriginIdName。账号需具备 acdn:EditDistribution 权限。
Token 获取方式见 密钥鉴权。
2. 输入参数¶
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| distributionId | 是 | Long | 分发主键 ID。示例值:34 |
| oldOriginIdName | 是 | String | 修改前的源名称。示例值:origin.example.com |
| domainName | 是 | String | 源域名。示例值:origin.example.com |
| originIdName | 是 | String | 新源名称(唯一)。示例值:origin.example.com |
| protocolPolicy | 是 | String | 协议策略。取值:http-only(仅 HTTP)、https-only(仅 HTTPS)、match-viewer(匹配查看器)。示例值:http-only |
| httpPort | 否 | Integer | HTTP 端口。默认值:80。示例值:80 |
| httpsPort | 否 | Integer | HTTPS 端口。默认值:443。示例值:443 |
| quantity | 否 | Integer | 最低源 SSL 协议档位。取值:1(TLSv1.2)、2(TLSv1.2+TLSv1.1)、3(至 TLSv1)、4(至 SSLv3)。示例值:1 |
| originPath | 否 | String | 源路径 |
| customHeaders | 否 | [CustomHeaders] | 自定义标头列表 |
| isOriginShield | 否 | Integer | 是否启用源护盾。取值:0(否)、1(是)。示例值:1 |
| originShieldRegion | 否 | String | 源护盾区域。取值:us-east-1、us-east-2、us-west-2、ap-south-1、ap-northeast-2、ap-southeast-1、ap-southeast-2、ap-northeast-1、eu-central-1、eu-west-1、eu-west-2、sa-east-1。示例值:us-east-1 |
| connectionAttempts | 否 | Integer | 连接尝试次数,范围 1–3。默认值:3。示例值:3 |
| connectionTimeout | 否 | Integer | 连接超时(秒),范围 1–10。默认值:10。示例值:10 |
| originReadTimeout | 否 | Integer | 响应超时(秒),范围 1–60。默认值:30。示例值:30 |
| originKeepaliveTimeout | 否 | Integer | 保持连接超时(秒),范围 1–60。默认值:5。示例值:5 |
3. 输出参数¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| code | Integer | 状态码。示例值:200 |
| msg | String | 提示信息。示例值:修改成功 |
4. 示例¶
示例1 修改源¶
输入示例¶
{
"oldOriginIdName": "origin.example.com",
"connectionAttempts": 3,
"originReadTimeout": 30,
"quantity": 1,
"httpPort": 80,
"connectionTimeout": 10,
"domainName": "origin.example.com",
"distributionId": 34,
"httpsPort": 443,
"customHeaders": [
{
"headerName": "X-Custom-Header",
"headerValue": "demo"
}
],
"originIdName": "origin.example.com",
"originPath": "",
"isOriginShield": 1,
"originKeepaliveTimeout": 5,
"originShieldRegion": "us-east-1",
"protocolPolicy": "http-only"
}
代码调用¶
请将 {登录域名}、token 替换为实际值。
curl -X POST 'https://{登录域名}/prod-api/acdn/originsRest/updateOrigins' \
-H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.xxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"oldOriginIdName": "origin.example.com",
"connectionAttempts": 3,
"originReadTimeout": 30,
"quantity": 1,
"httpPort": 80,
"connectionTimeout": 10,
"domainName": "origin.example.com",
"distributionId": 34,
"httpsPort": 443,
"customHeaders": [
{
"headerName": "X-Custom-Header",
"headerValue": "demo"
}
],
"originIdName": "origin.example.com",
"originPath": "",
"isOriginShield": 1,
"originKeepaliveTimeout": 5,
"originShieldRegion": "us-east-1",
"protocolPolicy": "http-only"
}'
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 UpdateOriginsTest {
public static void main(String[] args) throws Exception {
String url = "https://{登录域名}/prod-api/acdn/originsRest/updateOrigins";
String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";
String requestBody = "{"
+ "\"oldOriginIdName\":\"origin.example.com\","
+ "\"connectionAttempts\":3,"
+ "\"originReadTimeout\":30,"
+ "\"quantity\":1,"
+ "\"httpPort\":80,"
+ "\"connectionTimeout\":10,"
+ "\"domainName\":\"origin.example.com\","
+ "\"distributionId\":34,"
+ "\"httpsPort\":443,"
+ "\"customHeaders\":[{\"headerName\":\"X-Custom-Header\",\"headerValue\":\"demo\"}],"
+ "\"originIdName\":\"origin.example.com\","
+ "\"originPath\":\"\","
+ "\"isOriginShield\":1,"
+ "\"originKeepaliveTimeout\":5,"
+ "\"originShieldRegion\":\"us-east-1\","
+ "\"protocolPolicy\":\"http-only\""
+ "}";
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/originsRest/updateOrigins"
token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"
requestBody := []byte(`{
"oldOriginIdName": "origin.example.com",
"connectionAttempts": 3,
"originReadTimeout": 30,
"quantity": 1,
"httpPort": 80,
"connectionTimeout": 10,
"domainName": "origin.example.com",
"distributionId": 34,
"httpsPort": 443,
"customHeaders": [
{
"headerName": "X-Custom-Header",
"headerValue": "demo"
}
],
"originIdName": "origin.example.com",
"originPath": "",
"isOriginShield": 1,
"originKeepaliveTimeout": 5,
"originShieldRegion": "us-east-1",
"protocolPolicy": "http-only"
}`)
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 | 无权限 |
| 修改失败 | 修改未成功 |
6. 数据模型¶
CustomHeaders¶
自定义源请求头。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| headerName | 是 | String | 标头名。示例值:X-Custom-Header |
| headerValue | 是 | String | 标头值。示例值:demo |