首页 > 解决方案 > 无法在 ASP.Net 中使用 Godaddy API 更新域详细信息

问题描述

我正在尝试为当前使用 OTE 环境注册的域更新名称服务器。我能够注册域,但无法更新注册域的名称服务器。我收到的错误是

"INVALID_BODY\",\"fields\":[{\"code\":\"UNEXPECTED_TYPE\",\"message\":\"不是数组\",\"path\":\"records\ “}”

下面是我的代码。

GoDaddyDomain.cs

DomainUpdate sub = new DomainUpdate();


                sub.locked = true;
                sub.nameServers = new List<string>();
                sub.nameServers.Add("ns1.tsohost.co.uk");
                sub.nameServers.Add("ns2.tsohost.co.uk");
                sub.renewAuto = true;
                sub.subaccountId = "196209292";


                string _secret = "xxxx-xxxx-xxxx";
                string _apikey = "xxxx-xxxx-xxxx-xxxx-xxxx";

                string MessageType = "application/json";

                using (var client = new HttpClient())
                {

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("sso-key", _apikey + ":" + _secret);

                    using (var requests = new HttpRequestMessage(System.Net.Http.HttpMethod.Put, String.Format("https://api.ote-godaddy.com/v1/domains/MyTestDomain000001.com/records/")))
                    {
                        requests.Headers.Add("Accept", MessageType);


                        var response = new HttpResponseMessage();
                        var json = Newtonsoft.Json.JsonConvert.SerializeObject(sub);
                        requests.Content = new StringContent(value);
                        requests.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(MessageType);

                        using (var responses = await client.SendAsync(requests).ConfigureAwait(false))
                        {
                            string responseXmls = await responses.Content.ReadAsStringAsync().ConfigureAwait(false);

                            var codes = response.StatusCode;
                        }
                        requests.Content.Dispose();
                    }

                }

            }
            catch (Exception ex) { }

域更新.cs

public class DomainUpdate
    {
        public bool locked { get; set; }
        public List<string> nameServers { get; set; }
        public bool renewAuto { get; set; }
        public string subaccountId { get; set; }
    }

标签: asp.netgodaddy-api

解决方案


推荐阅读