gpt4 book ai didi

c# - Azure 服务管理 Api 配置更改(400 错误请求错误)

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

我正在尝试使用 azure 管理 API 上传配置文件。我收到 400 bad request 错误,我不明白为什么,有什么建议吗?

这里是更改配置操作的 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();

}

}

最佳答案

服务器的响应没有正文吗?

看起来,当您构建 URL 时,您在需要“deploymentSlot”的地方使用了“deploymentName”。会是这样吗?

关于c# - Azure 服务管理 Api 配置更改(400 错误请求错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9694779/

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