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

本文关键字:错误 请求 服务 管理 Api 配置 Azure | 更新日期: 2023-09-27 18:27:38

我正在尝试使用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();
    }
}

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

服务器的响应是否没有正文?

看起来,当你构建URL时,你在想要"deploymentSlot"的地方使用了"deployentName"。可能是这样吗?