Azure, BadRequest: The body of the request is empt

2019-09-12 01:46发布

问题:

This started out as a SubscriptionNotFound error.

Then I ended up with a MissingRegistrationForLocation error.

And now I'm here.

Same code:

var dnsClient = new DnsManagementClient(new Microsoft.Azure.TokenCloudCredentials(result.AccessToken));

var zone = dnsClient.Zones.CreateOrUpdate("someresourcegroup", "mydomain.com", new Microsoft.Azure.Management.Dns.Models.ZoneCreateOrUpdateParameters {
    IfNoneMatch = "*",
    Zone = new Microsoft.Azure.Management.Dns.Models.Zone {
        Name = "mydomain.com",
        Location = "global"
    }
});

And this bug:

BadRequest: The body of the request is empty or does not have the expected content.

The other 2 errors makes sense, but this one seems a bit like a dead-end.

What Am I doing wrong this time around?

回答1:

Please change your code and include Properties:

        var zone = dnsClient.Zones.CreateOrUpdate("someresourcegroup", "mydomain.com", new Microsoft.Azure.Management.Dns.Models.ZoneCreateOrUpdateParameters
        {
            IfNoneMatch = "*",
            Zone = new Microsoft.Azure.Management.Dns.Models.Zone
            {
                Name = "mydomain.com",
                Location = "global",
                Properties = new ZoneProperties()//Add this line!
            }
        });

That should take care of the problem.