0

我正在使用 godaddy api 访问域。我被推荐了, https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplace

我想在 Godaddy 的域中添加 CNAME。

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", "sso-key {key}:{secret}");
                var requestURl = "https://api.godaddy.com/v1/domains/mydomain.com/";
                string body = "{\"data\": \"xxxxx.azurewebsites.net\",\"name\": \"xxxx\",\"type\": \"CNAME\"}";



                var stringContent = new StringContent(body, Encoding.UTF8, "application/json");
                var response = client.GetAsync(requestURl).GetAwaiter().GetResult(); ;
                if (response.StatusCode == HttpStatusCode.Created)
                {

                }
            }

但我收到错误代码 422。知道为什么会出现这些错误吗?

4

1 回答 1

1

终于有答案了

         using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("Authorization", "sso-key {key}:{secret}");
            var requestURl = "https://api.godaddy.com/v1/domains/mydomain.com/";
         var data = new
                {
                    data= "xxxxx.azurewebsites.net",
                    name = "xxxx",
                    type = "CNAME",
                    ttl =3600
                };
                var body = JsonConvert.SerializeObject(data);


           var stringContent = new StringContent("["+body+"]", Encoding.UTF8, "application/json");
              var responseMessage = await client.PatchAsync(new Uri(requestURl), stringContent);
            if (response.StatusCode == HttpStatusCode.Created)
            {

            }
        }
于 2018-10-10T10:14:05.137 回答