有人能给我解释一下使用GoDaddy API更新域的A记录实际所需的JSON模式是什么吗?我已经尝试了我在网上找到的JSON模式的变体,包括他们自己的最新文档,但永远无法让它工作。
然而,我可以做任何和所有的GETs没有一个单一的问题。
我得到的错误是一个422 http响应,根据他们自己的文档,这意味着发送的JSON格式不正确/不符合模式。
下面是用于提交请求的代码,后面是我尝试使用的JSON格式...
private async Task UpdateDNS()
{
string domainName = "THISISMINE"; // my GoDaddy domain name
string newIPAddress = GetIPAddress(); ; // My new IP address
// Authenticate with the GoDaddy API using API key and secret
string apiKey = "MY_PRODUCTION_API_KEY";
string apiSecret = "MY_PRODUCTION_SECRET";
string OTEKey = "MY_OTE_KEY";
string OTESecret = "MY_OTE_SECRET";
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("sso-key", $"{apiKey}:{apiSecret}");
// Get the domain details from the GoDaddy API
string getDomainURL = $"https://api.godaddy.com/v1/domains/{domainName}";
HttpResponseMessage response = await httpClient.GetAsync(getDomainURL);
if (!response.IsSuccessStatusCode)
{
this.textBox1.Text += "[" + DateTime.Now.ToLongTimeString() + "]: Failed to retrieve [GENERAL] domain details." + Environment.NewLine + Environment.NewLine;
return;
}
string worker_json = await response.Content.ReadAsStringAsync();
GoDaddyDomainInfo DomainInfo = JsonConvert.DeserializeObject<GoDaddyDomainInfo>(thejson);
//Get the A record
string aRecordName = "@";
string aRecordURL = $"https://api.godaddy.com/v1/domains/{domainName}/records/A/{aRecordName}";
//var updateRecordContent = new { data = newIPAddress };
response = await httpClient.GetAsync(aRecordURL);
if (!response.IsSuccessStatusCode)
{
this.textBox1.Text += "[" + DateTime.Now.ToLongTimeString() + "]: Failed to retrieve [A_RECORD] details for domain." + Environment.NewLine + Environment.NewLine;
return;
}
worker_json = await response.Content.ReadAsStringAsync();
List<GoDaddy_ARecord_Info> ARecordInfo = JsonConvert.DeserializeObject<List<GoDaddy_ARecord_Info>>(worker_json);
ARecordInfo[0].data = newIPAddress;
// Update the A record with the new IP address
string updateRecordURL = $"https://api.godaddy.com/v1/domains/{domainName}/records/A/@";
string jsonOUT = JsonConvert.SerializeObject(ARecordInfo);
response = await httpClient.PutAsJsonAsync(updateRecordURL, jsonOUT);
//THIS ALWAYS RETURNS 422 NO MATTER WHAT THE JSON LOOKS LIKE
if (!response.IsSuccessStatusCode)
{
this.textBox1.Text += "[" + DateTime.Now.ToLongTimeString() + "]: Failed to UPDATE [A_RECORD] on GoDaddy." + Environment.NewLine + Environment.NewLine;
return;
}
string p = $"IP address for {domainName} updated to {newIPAddress}.";
}
以下是尝试但未成功的不同JSON输出:[{"data":"xxx.xx.xx.xxx","ttl":3600}]
[{"data":"xxx.xx.xx.xxx","name":"@","ttl":3600,"type":"A"}]
[{"data":"xxx.xx.xx.xxx","name":"record","ttl":3600,"type":"A"}]
[{"data":"xxx.xx.xx.xxx","name":"%40","ttl":3600,"type":"A"}]
[{ "data": "xxx.xx.xx.xxx","name": "@","port": 65535,"priority": 0,"protocol": "string","service": "string","ttl": 3600,"type": "A","weight": 0}]
请帮助...这应该是超简单的性质,但...
1条答案
按热度按时间elcex8rz1#
这个bug是在使用AsJSon的时候。当你使用ASJson的时候你不应该序列化数据
或者其他最常见的语法