CDN使用JAVA SDK刷新缓存示例代码
详细解答可以参考官方帮助文档 CDN提供了JAVA、python、php、.Net等多种语言的SDK:SDK详情介绍。以下简单介绍使用SDK刷新缓存的使用方法:一、引入SDK请在pom.xml文件中增加以下依赖, 准确的SDK版本号, 请参考SDK详情.二、初始化ClientSDK通过IAcsClient的instance来完成openapi的调用, 因此在您发起调用前, 请先初始化IAcsClient实例. 示例代码如下:public void init() throws ClientException { IClientProfile profile = DefaultProfile.getProfile('cn-hangzhou', '', ''); client = new DefaultAcsClient(profile); }三、构造刷新请求完整的示例代码如下: package aliyun.sdk.cdn;import com.aliyuncs.DefaultAcsClient;import com.aliyuncs.cdn.model.v20141111.PurgeObjectCachesRequest;import com.aliyuncs.exceptions.ClientException;import com.aliyuncs.exceptions.ServerException;import com.aliyuncs.http.HttpResponse;import com.aliyuncs.profile.DefaultProfile;import com.aliyuncs.profile.IClientProfile;public class cdntest { public static DefaultAcsClient client; public static void main(String[] args) throws ClientException { // TODO Auto-generated method stub init(); PurgeObjectCaches(); } public static void init() throws ClientException { IClientProfile profile = DefaultProfile.getProfile('cn-hangzhou', '', ''); client = new DefaultAcsClient(profile); } public static void PurgeObjectCaches() { PurgeObjectCachesRequest request = new PurgeObjectCachesRequest(); //要刷新的域名 request.setDomainName('www.abc.com'); //要刷新的URI request.setObjectPath('/abc/1.png'); //刷新类型,默认是File request.setObjectType('File'); try { HttpResponse httpResponse = client.doAction(request); System.out.println(httpResponse.getUrl()); System.out.println(new String(httpResponse.getContent())); //todo something. } catch (ServerException e) { e.printStackTrace(); } catch (ClientException e) { e.printStackTrace(); } }}如问题还未解决,请联系售后技术支持。
赞0
踩1