我正在尝试使用azure管理API上传配置文件。我收到400错误的请求错误,我无法弄清楚为什么,任何建议?
以下是更改配置操作的API文档。 http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx
这是我的代码。任何回应都非常感激
public void changeConfiguration(string serviceName, string deploymentSlot, string config, string deploymentName)
{
byte[] encodedConfigbyte = new byte[config.Length];
encodedConfigbyte = System.Text.Encoding.ASCII.GetBytes(config);
string temp = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(config));
Uri changeConfigRequestUri = new Uri("https://management.core.windows.net/" + subscriptionId + "/services/hostedservices/" + serviceName + "/deploymentslots/" + deploymentName + "/?comp=config");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(changeConfigRequestUri);
request.Headers.Add("x-ms-version", "2010-10-28");
request.Method = "POST";
string bodyText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<ChangeConfiguration xmlns=\"http://schemas.microsoft.com/windowsazure\"" + ">"
+ "<Configuration>" + temp + "</Configuration> </ChangeConfiguration>";
byte[] buf = Encoding.ASCII.GetBytes(bodyText);
request.ContentType = "application/xml";
request.ContentLength = buf.Length;
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
try
{
certStore.Open(OpenFlags.ReadOnly);
}
catch (Exception e)
{
if (e is CryptographicException)
{
Console.WriteLine("Error: The store is unreadable.");
}
else if (e is SecurityException)
{
Console.WriteLine("Error: You don't have the required permission.");
}
else if (e is ArgumentException)
{
Console.WriteLine("Error: Invalid values in the store.");
}
else
{
throw;
}
}
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
certStore.Close();
if (certCollection.Count == 0)
{
throw new Exception("Error: No certificate found containing thumbprint ");
}
X509Certificate2 certificate = certCollection[0];
request.ClientCertificates.Add(certificate);
Stream dataStream = request.GetRequestStream();
dataStream.Write(buf, 0, buf.Length);
dataStream.Close();
//Error occurs in the line below
WebResponse response = (HttpWebResponse)request.GetResponse();
}
}
答案 0 :(得分:1)
服务器的响应是否没有主体?
看起来当你构建你的URL时,你正在使用“deploymentName”,你想要“deploymentSlot”。可能是吗?