预热 URL¶
1. 接口描述¶
接口请求路径:POST /prod-api/acdn/dcdn/refreshCacheRest/pushObjectCache
pushObjectCache 用于对国内 DCDN 加速域名发起 URL 预热任务,将指定资源预取至边缘节点。objectPath 支持多行,每行一条完整 URL(须以 http:// 或 https:// 开头)。
Token 获取方式见 密钥鉴权。
2. 输入参数¶
以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| objectPath | 是 | String | 待预热的 URL。多条用换行分隔,每条须包含 http:// 或 https://,且域名须为本账号下已接入的 DCDN 域名示例值: https://demo.123.com/ |
3. 示例¶
示例1 预热单个 URL¶
输入示例¶
代码调用¶
请将 {登录域名}、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 PushObjectCacheTest {
public static void main(String[] args) throws Exception {
String url = "https://{登录域名}/prod-api/acdn/dcdn/refreshCacheRest/pushObjectCache";
String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";
String requestBody = "{\"objectPath\":\"https://demo.123.com/\"}";
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/dcdn/refreshCacheRest/pushObjectCache"
token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"
requestBody := []byte(`{
"objectPath": "https://demo.123.com/"
}`)
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))
}
输出示例¶
4. 输出参数¶
| 参数名称 | 类型 | 描述 |
|---|---|---|
| code | Integer | 状态码。示例值:200 |
| msg | String | 提示信息。示例值:success |
5. 错误码¶
| HTTP 状态码 / 业务提示 | 描述 |
|---|---|
| 200 | 成功 |
| 401 | 未鉴权或 Token 无效 |
| 403 | 无权限 |
| 保存失败,请确认参数是否合法 | 未传入 objectPath 或请求体为空 |
| URL需要http://或https:// | URL 未包含协议头 |
| 输入的url中,包含无效的域名 | URL 中的域名未接入或不属于当前账号 |