开发者社区> 问答> 正文

云解析的SDK

目前阿里云官方提供的 SDK 分4种语言版本,分别为 Java、Python、PHP、C#,具体链接如下:


更多语言版本的 SDK,您可以前往 第三方 SDK 服务中进行选择。
相关信息: 关于AccessKey的获取

SDK安装


通过maven进行安装添加maven库
  1. [backcolor=transparent]<repositories>
  2. [backcolor=transparent]        [backcolor=transparent]<repository>
  3. [backcolor=transparent]            [backcolor=transparent]<id>[backcolor=transparent]sonatype-nexus-staging[backcolor=transparent]</id>
  4. [backcolor=transparent]            [backcolor=transparent]<name>[backcolor=transparent]Sonatype Nexus Staging[backcolor=transparent]</name>
  5. [backcolor=transparent]            [backcolor=transparent]<url>[backcolor=transparent]https://oss.sonatype.org/service/local/staging/deploy/maven2/[backcolor=transparent]</url>
  6. [backcolor=transparent]            [backcolor=transparent]<releases>
  7. [backcolor=transparent]                [backcolor=transparent]<enabled>[backcolor=transparent]true[backcolor=transparent]</enabled>
  8. [backcolor=transparent]            [backcolor=transparent]</releases>
  9. [backcolor=transparent]            [backcolor=transparent]<snapshots>
  10. [backcolor=transparent]                [backcolor=transparent]<enabled>[backcolor=transparent]true[backcolor=transparent]</enabled>
  11. [backcolor=transparent]            [backcolor=transparent]</snapshots>
  12. [backcolor=transparent]        [backcolor=transparent]</repository>
  13. [backcolor=transparent]</repositories>

添加jar包依赖
  1. [backcolor=transparent]<dependency>
  2. [backcolor=transparent]      [backcolor=transparent]<groupId>[backcolor=transparent]com.aliyun[backcolor=transparent]</groupId>
  3. [backcolor=transparent]      [backcolor=transparent]<artifactId>[backcolor=transparent]aliyun-java-sdk-alidns[backcolor=transparent]</artifactId>
  4. [backcolor=transparent]      [backcolor=transparent]<version>[backcolor=transparent]2.0.1[backcolor=transparent]</version>
  5. [backcolor=transparent]</dependency>
  6. [backcolor=transparent]<dependency>
  7. [backcolor=transparent]      [backcolor=transparent]<groupId>[backcolor=transparent]com.aliyun[backcolor=transparent]</groupId>
  8. [backcolor=transparent]      [backcolor=transparent]<artifactId>[backcolor=transparent]aliyun-java-sdk-core[backcolor=transparent]</artifactId>
  9. [backcolor=transparent]      [backcolor=transparent]<version>[backcolor=transparent]2.3.8[backcolor=transparent]</version>
  10. [backcolor=transparent]</dependency>


示例代码

  1. [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]DemoListDomains[backcolor=transparent] [backcolor=transparent]{
  2. [backcolor=transparent]    [backcolor=transparent]private[backcolor=transparent] [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]IAcsClient[backcolor=transparent] client [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]null[backcolor=transparent];
  3. [backcolor=transparent]    [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]{
  4. [backcolor=transparent]        [backcolor=transparent]String[backcolor=transparent] regionId [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]"cn-hangzhou"[backcolor=transparent];[backcolor=transparent] [backcolor=transparent]//必填固定值,必须为“cn-hanghou”
  5. [backcolor=transparent]        [backcolor=transparent]String[backcolor=transparent] accessKeyId [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]""[backcolor=transparent];[backcolor=transparent] [backcolor=transparent]// your accessKey
  6. [backcolor=transparent]        [backcolor=transparent]String[backcolor=transparent] accessKeySecret [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]""[backcolor=transparent];[backcolor=transparent]// your accessSecret
  7. [backcolor=transparent]        [backcolor=transparent]IClientProfile[backcolor=transparent] profile [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]DefaultProfile[backcolor=transparent].[backcolor=transparent]getProfile[backcolor=transparent]([backcolor=transparent]regionId[backcolor=transparent],[backcolor=transparent] accessKeyId[backcolor=transparent],[backcolor=transparent] accessKeySecret[backcolor=transparent]);
  8. [backcolor=transparent]        [backcolor=transparent]// 若报Can not find endpoint to access异常,请添加以下此行代码
  9. [backcolor=transparent]        [backcolor=transparent]// DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Alidns", "alidns.aliyuncs.com");  
  10. [backcolor=transparent]        client [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]DefaultAcsClient[backcolor=transparent]([backcolor=transparent]profile[backcolor=transparent]);
  11. [backcolor=transparent]    [backcolor=transparent]}
  12. [backcolor=transparent]    [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] main[backcolor=transparent]([backcolor=transparent]String[backcolor=transparent][][backcolor=transparent] args[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  13. [backcolor=transparent]        [backcolor=transparent]DescribeDomainsRequest[backcolor=transparent] request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]DescribeDomainsRequest[backcolor=transparent]();
  14. [backcolor=transparent]        [backcolor=transparent]DescribeDomainsResponse[backcolor=transparent] response[backcolor=transparent];
  15. [backcolor=transparent]        [backcolor=transparent]// describeRegionsRequest.setProtocol(ProtocolType.HTTPS); //指定访问协议
  16. [backcolor=transparent]        [backcolor=transparent]// describeRegionsRequest.setAcceptFormat(FormatType.JSON); //指定api返回格式
  17. [backcolor=transparent]        [backcolor=transparent]// describeRegionsRequest.setMethod(MethodType.POST); //指定请求方法
  18. [backcolor=transparent]        [backcolor=transparent]// describeRegionsRequest.setRegionId("cn-hangzhou");//指定要访问的Region,仅对当前请求生效,不改变client的默认设置。
  19. [backcolor=transparent]        [backcolor=transparent]try[backcolor=transparent] [backcolor=transparent]{
  20. [backcolor=transparent]            response [backcolor=transparent]=[backcolor=transparent] client[backcolor=transparent].[backcolor=transparent]getAcsResponse[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
  21. [backcolor=transparent]            [backcolor=transparent]List[backcolor=transparent]<[backcolor=transparent]Domain[backcolor=transparent]>[backcolor=transparent] list [backcolor=transparent]=[backcolor=transparent] response[backcolor=transparent].[backcolor=transparent]getDomains[backcolor=transparent]();
  22. [backcolor=transparent]            [backcolor=transparent]for[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]Domain[backcolor=transparent] domain [backcolor=transparent]:[backcolor=transparent] list[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  23. [backcolor=transparent]                [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]domain[backcolor=transparent].[backcolor=transparent]getDomainName[backcolor=transparent]());
  24. [backcolor=transparent]            [backcolor=transparent]}
  25. [backcolor=transparent]        [backcolor=transparent]}[backcolor=transparent] [backcolor=transparent]catch[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]ServerException[backcolor=transparent] e[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  26. [backcolor=transparent]            e[backcolor=transparent].[backcolor=transparent]printStackTrace[backcolor=transparent]();
  27. [backcolor=transparent]        [backcolor=transparent]}[backcolor=transparent] [backcolor=transparent]catch[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]ClientException[backcolor=transparent] e[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
  28. [backcolor=transparent]            e[backcolor=transparent].[backcolor=transparent]printStackTrace[backcolor=transparent]();
  29. [backcolor=transparent]        [backcolor=transparent]}
  30. [backcolor=transparent]    [backcolor=transparent]}
  31. [backcolor=transparent]}

展开
收起
boxti 2017-10-18 13:50:03 1589 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
从 SDK 到编解码:视频直播架构解析 立即下载
跨平台的云服务SDK需要什么 立即下载
一个跨平台的云服务SDK需要什么 立即下载

相关镜像