gpt4 book ai didi

Azure 管理服务 API 以某种加密格式提供部署配置

转载 作者:行者123 更新时间:2023-12-03 06:03:57 25 4
gpt4 key购买 nike

我正在使用此代码来获取部署配置。

X509Store certificateStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
certificateStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = certificateStore.Certificates.Find(
X509FindType.FindByThumbprint, certThumb, false);
if (certs.Count == 0)
{
Console.WriteLine("Couldn't find the certificate with thumbprint:" + certThumb);
return;
}
certificateStore.Close();

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(
new Uri("https://management.core.windows.net/" + subID +
"/services/hostedservices/" + hostedServiceName +
"/deploymentslots/" + deploymentType));
request.Method = "GET";
request.ClientCertificates.Add(certs[0]);
request.ContentType = "application/xml";
request.Headers.Add("x-ms-version", "2009-10-01");
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
// Parse the web response.
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

// Display the raw response.
Console.WriteLine("Deployment Details:");
string deployment = reader.ReadToEnd();

// Close the resources no longer needed.
responseStream.Close();
}

但我得到的是加密格式的配置。

但是如果运行 azure powershell,它会以纯文本形式提供配置。

$deployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
$deployedConfig = $deployment.Configuration

既然我必须使用服务管理API,我该怎么做?

最佳答案

这是expected behavior 。 REST API 以 Base64 编码格式返回数据。由于 Windows Azure PowerShell 使用相同的 REST API,因此它们将数据从 Base64 格式转换并以人类可读的格式呈现。这也是您需要做的。

所以在你的代码中你会做这样的事情:

string clearText = System.Text.Encoding.UTF8.GetString(
Convert.FromBase64String(reader.ReadToEnd()));

关于Azure 管理服务 API 以某种加密格式提供部署配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17849681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com