我正在使用 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。知道为什么会出现这些错误吗?
终于得到了答案,
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)
{
}
}