0

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

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,我该怎么做?

4

1 回答 1

2

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

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

string clearText = System.Text.Encoding.UTF8.GetString(
                      Convert.FromBase64String(reader.ReadToEnd()));
于 2013-07-25T06:01:31.197 回答