调用Godaddy API将指定的DNS记录添加到指定的域时,Doamin错误

时间:2018-10-08 12:35:24

标签: godaddy-api

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

我想在Godaddy的doamin中添加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。为什么会出现这些错误?

1 个答案:

答案 0 :(得分: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)
            {

            }
        }