.NET SDK 示例

安装 SDK

.NET SDK 使用说明:https://help.aliyun.com/document_detail/66509.html

调用 Codeup API

以 CreateRepository 为例:

using System;
using System.Collections.Generic;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;

namespace CommonRequestDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
            DefaultAcsClient client = new DefaultAcsClient(profile);
            CommonRequest request = new CommonRequest();
            request.Method = MethodType.POST;
            request.Domain = "codeup.cn-hangzhou.aliyuncs.com";
            request.Version = "2020-04-14";
            request.UriPattern = "/api/v3/projects";
            // request.Protocol = ProtocolType.HTTP;
            request.AddQueryParameters("OrganizationId", "<OrganizationId>");
            request.AddHeadParameters("Content-Type", "application/json");
            string requestBody = "" +
                "{" +
                "    \"name\": \"<RepoName>\"," +
                "    \"path\": \"<RepoPath>\"," +
                "    \"visibility_level\": 10," +
                "    \"namespace_id\": 123" +
                "}";
            request.SetContent(System.Text.Encoding.Default.GetBytes(requestBody), "utf-8", FormatType.JSON);

            try {
                CommonResponse response = client.GetCommonResponse(request);
                Console.WriteLine(response.Data);
            }
            catch (ServerException e)
            {
                Console.WriteLine(e);
            }
            catch (ClientException e)
            {
                Console.WriteLine(e);
            }
        }
    }
}