我正在尝试编写一个本地控制台应用程序,它将使用Azure REST API交换一个 Azure Web App 插槽。使用以下代码,我得到 401(未经授权)响应:
public async Task Swap(string subscription, string resourceGroup, string site, string slot)
{
var client = new HttpClient();
var url =
$"https://management.azure.com/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Web/sites/{site}/applySlotConfig?api-version=2016-08-01";
var data = new {preserveVnet = true, targetSlot = slot};
var message = new HttpRequestMessage
{
RequestUri = new Uri(url),
Method = HttpMethod.Post,
Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")
};
var response = await client.SendAsync(message);
Console.WriteLine(response.StatusCode);
}
我知道我需要输入某种凭据,但我发现的似乎适用于使用 Azure AD 进行身份验证的应用程序。这将是一个具有匿名身份验证的可公开访问的 Web 应用程序。