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

标签 c# api post configuration azure

我正在尝试使用 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/

相关文章:

api - 哪个 Amadeus API 将返回航类详细信息和价格?

post - 在 Erlang 中的 HTTPC 发布请求中设置 header

php - 如何用php向数据库中插入多个数据

c# - 何时在自定义控件中使用属性而不是依赖属性?

c# - 在 WCF 服务中实现缓存

c# - 注册流程开始时间的最佳方式?

c - 在 C 中安全重启 linux

api - 如何使用 Karate 工具和特征文件比较包含数组的 2 个 JSON 对象

python - 如何在 python 和 webapp2 中发出 POST 请求

C# DLL 菜鸟,如何获取函数