gpt4 book ai didi

c# - 400 错误请求,Azure 服务管理 api 配置更改

转载 作者:行者123 更新时间:2023-11-30 18:00:46 26 4
gpt4 key购买 nike

我的问题是,当我尝试获取对 HTTP 请求的响应时,收到 400 错误请求。谁能告诉我为什么会发生这种情况以及我该如何解决它?

确切的错误是: BadRequest未更改指定的设置

在传递配置文件之前,我在代码中放置了一个断点,当我查看它时,它已经更改了我想要更改的内容,因此已经存在的配置文件与我正在尝试的配置文件明显不同来改变它。

以下是配置更改的 API 信息:http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx

下面是我的代码,非常感谢任何帮助,谢谢

public void changeConfiguration(string serviceName, string deploymentSlot, string  config, string deploymentName)
{
//encoding the config file
byte[] encodedConfigbyte = new byte[config.Length];
encodedConfigbyte = System.Text.Encoding.UTF8.GetBytes(config);
string temp = Convert.ToBase64String(encodedConfigbyte);

//creating the URI with the subscriptionID,serviceName and deploymentSlot
Uri changeConfigRequestUri = new Uri("https://management.core.windows.net/" + subscriptionId + "/services/hostedservices/" + serviceName + "/deploymentslots/" + deploymentSlot + "/?comp=config");

//creating a request using the URI
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(changeConfigRequestUri);

//Adding a header to the request
request.Headers.Add("x-ms-version", "2010-10-28");
request.Method = "POST";

//Create a string to hold the request body, temp being the config file
string bodyText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<ChangeConfiguration xmlns=\"http://schemas.microsoft.com/windowsazure\"" + ">"
+ "<Configuration>" + temp + "</Configuration></ChangeConfiguration>";

//encoding the body
byte[] buf = Encoding.ASCII.GetBytes(bodyText);
request.ContentType = "application/xml";
request.ContentLength = buf.Length;

//searches the cert store for a cert that has a matching thumbprint to the thumbprint supplied
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];

//cert is added to the request
request.ClientCertificates.Add(certificate);

//the requestBody is written to the request
Stream dataStream = request.GetRequestStream();
dataStream.Write(buf, 0, buf.Length);
dataStream.Close();
try
{
//retrieving responce
WebResponse response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
string test = new StreamReader(e.Response.GetResponseStream()).ReadToEnd();
}
}

}

最佳答案

BadRequest 表示参数不正确。我的猜测是您使用的是 0 的DeploymentSlot,而不是像这里提到的那样进行暂存或生产:

http://msdn.microsoft.com/en-us/library/ee460786.aspx

除此之外,如果您可以向我们展示您传入的参数,我们也许可以从中看出问题所在,那就太好了。

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

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