azure mysql rest api插入新防火墙规则

zqdjd7g9  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(395)

我正在尝试创建新的防火墙规则。我没有问题更新现有的规则,但我不能创建新的。我得到了真实的状态码响应,但在azure门户中看不到结果(几分钟后)。附加的代码属于一个web应用,其角色与mysql组资源相对应。我做错了什么?

private static string URI_FIREWALL_BASE = "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/MY_RESOURCE/providers/Microsoft.DBforMySQL/servers/MYSERVER/firewallRules/";

public string AddIPFirewallRule(string email, string IP)
    {
        AuthenticationResult token = AsyncContext.Run(() => AzureActiveDirectory.GetS2SAccessTokenForProdMSAAsync());
        HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);

        JObject NewRule =
            new JObject(
            new JProperty("properties",
                new JObject(
                    new JProperty("startIpAddress", IP),
                    new JProperty("endIpAddress", IP)
                    )));

        var content = JsonConvert.SerializeObject(NewRule);
        var httpContent = new StringContent(content, Encoding.UTF8, "application/json"); 

        HttpResponseMessage resp = AsyncContext.Run(() => client.PutAsync(URI_FIREWALL_BASE + $"{email}?api-version=2017-12-01", httpContent));
        return AsyncContext.Run(() => resp.Content.ReadAsStringAsync());
    }
x4shl7ld

x4shl7ld1#

我终于明白了。我必须遵循一些规则来命名新服务,正如你在azureportal桌面上看到的那样。

相关问题