C# Azure服务管理Api配置更改(400错误请求错误)
我正在尝试使用azure管理api上载配置文件。我收到一个400错误的请求,我不知道为什么,有什么建议吗 以下是更改配置操作的API文档。 这是我的密码。非常感谢您的回复C# Azure服务管理Api配置更改(400错误请求错误),c#,api,post,configuration,azure,C#,Api,Post,Configuration,Azure,我正在尝试使用azure管理api上载配置文件。我收到一个400错误的请求,我不知道为什么,有什么建议吗 以下是更改配置操作的API文档。 这是我的密码。非常感谢您的回复 public void changeConfiguration(string serviceName, string deploymentSlot, string config, string deploymentName) { byte[] encodedConfigbyte = new byte
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();
}
}
public void changeConfiguration(string serviceName、string deploymentSlot、string config、string deploymentName)
{
字节[]encodedConfigbyte=新字节[config.Length];
encodedConfigbyte=System.Text.Encoding.ASCII.GetBytes(配置);
string temp=Convert.ToBase64String(ascienceoding.ASCII.GetBytes(config));
Uri changeConfigRequestUri=新Uri(“https://management.core.windows.net/“+subscriptionId+”/services/hostedservices/“+serviceName+”/deploymentslots/“+deploymentName+”/?comp=config”);
HttpWebRequest请求=(HttpWebRequest)HttpWebRequest.Create(changeConfigRequestUri);
请求。标题。添加(“x-ms-version”、“2010-10-28”);
request.Method=“POST”;
字符串bodyText=“”+
""
+“+temp+”;
byte[]buf=Encoding.ASCII.GetBytes(bodyText);
request.ContentType=“应用程序/xml”;
request.ContentLength=buf.Length;
X509Store certStore=新的X509Store(StoreName.My,StoreLocation.CurrentUser);
尝试
{
打开(OpenFlags.ReadOnly);
}
捕获(例外e)
{
if(e是加密例外)
{
WriteLine(“错误:存储不可读。”);
}
else if(e为安全例外)
{
WriteLine(“错误:您没有所需的权限。”);
}
else if(e为异常)
{
WriteLine(“错误:存储中的值无效。”);
}
其他的
{
投掷;
}
}
X509Certificate2Collection-certCollection=certStore.Certificates.Find(X509FindType.FindByThumbprint,指纹,false);
certStore.Close();
如果(certCollection.Count==0)
{
抛出新异常(“错误:未找到包含指纹的证书”);
}
X509Certificate2 certificate=certCollection[0];
request.ClientCertificates.Add(证书);
Stream dataStream=request.GetRequestStream();
dataStream.Write(buf,0,buf.Length);
dataStream.Close();
//错误发生在下面的行中
WebResponse=(HttpWebResponse)request.GetResponse();
}
}
服务器的响应是否没有正文
看起来,在构建URL时,您在需要“deploymentSlot”的位置使用了“deploymentName”。可能是这样吗?服务器的响应没有正文吗
看起来,当您构建URL时,您在想要“deploymentSlot”的地方使用了“deploymentName”。是这样吗?谢谢您的回复,我不确定响应的主体,但文档中说我可以使用部署名称或部署插槽,但如果您使用部署名称,然后URL需要如下所示:
https://management.core.windows.net//services/hostedservices//deployments//?comp=config
您的URL看起来像是使用部署槽的URL。很好,您是对的,我确实有错误的URL,但我已将其更改为Uri changeConfigRequestUri=new Uri("https://management.core.windows.net/“+subscriptionId+”/services/hostedservices/“+serviceName+”/deployments/“+deploymentName+”/?comp=config”);
我仍然收到400个错误请求。您确定“deploymentName”是正确的吗?(我不相信门户会向您显示部署名称……如果您通过门户创建部署,我认为这是一个GUID。)我认为400响应的主体会很有帮助。捕获异常并阅读响应。您对部署名称的看法是正确的,我输入了id,我硬编码了正确的名称,但我仍然收到400错误的请求,异常响应不会给我任何新的信息。谢谢您的回复,我对主体不太确定响应,但文档说我可以使用部署名称或部署槽,但如果使用部署名称,则URL需要如下所示:https://management.core.windows.net//services/hostedservices//deployments//?comp=config
您的URL看起来像是使用部署槽的URL。很好地发现,您是正确的t、 我确实有错误的URL,但我已将其更改为urichangeconfigrequesturi=newURI(“https://management.core.windows.net/“+subscriptionId+”/services/hostedservices/“+serviceName+”/deployments/“+deploymentName+”/?comp=config”);
我仍然收到400个错误请求,您确定”deploymentName“是正确的吗?(我不相信门户会向您显示部署名称…如果您通过门户创建部署,我认为这是一个GUID。)我认为400响应的主体会很有帮助。捕获异常并阅读响应。关于部署名称,您是对的,我输入了id,我硬编码了正确的名称,但我仍然收到400错误请求,异常响应不会给我任何新信息