【发布时间】:2019-02-11 00:55:51
【问题描述】:
在我的项目中,每当调用 API 时,它都会缓存在 Akamai 中。但是当客户端通过 UI 更改数据库中的某些内容时。我们需要在 AKAMAI 中使缓存的 API 响应无效,并用新的新鲜 json 数据填充它。我在互联网上找到了一些链接:akamai-purging 但我无法理解他们在谈论的这个链接中的 cp-code 是什么?
这是我给出的示例代码:405 Not Allowed
代码:
public static void main(String[] args) throws IOException, RequestSigningException {
URL url = new URL("https://xxx-host-name-/scripts.4535eaf743502b25ba3a.js");
HttpTransport HTTP_TRANSPORT = new ApacheHttpTransport();
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
AkamaiPostData postData = new AkamaiPostData();
postData.setHostname(AkamaiConstants.SITE_HOST_NAME);
Gson gson = new Gson();
String postDataJSON = gson.toJson(postData);
byte[] contentBytes = postDataJSON.getBytes();
HttpContent content = new ByteArrayContent("application/json", contentBytes);
HttpRequest request = requestFactory.buildDeleteRequest(new GenericUrl(url));
HttpHeaders headers = request.getHeaders();
headers.set("Host", "xxx-host-name-");
ClientCredential credential = new DefaultCredential(AkamaiConstants.CLIENT_TOKEN, AkamaiConstants.ACCESS_TOKEN, AkamaiConstants.CLIENT_SECRET);
RequestSigner signer = new EdgeGridV1Signer(Collections.EMPTY_LIST, 1024 * 2);
HttpRequest signedRequest = signer.sign(request, credential);
HttpResponse response = signedRequest.execute();
String result = response.parseAsString();
System.out.println("result::" + result);
}
【问题讨论】:
标签: java rest cdn akamai purge