如何使用REST Api在Windows Azure中列出管理证书
发布时间:2020-12-14 05:27:59 所属栏目:Windows 来源:网络整理
导读:我想在 windows azure子目录中列出所有管理证书.我尝试使用以下代码.但它给了我一个例外.我可以发现响应为空,异常消息是“远程服务器返回错误:(403)禁止.” 请帮我解决一下这个. Msdn不提供此示例:( using System;using System.Collections.Generic;using S
我想在
windows azure子目录中列出所有管理证书.我尝试使用以下代码.但它给了我一个例外.我可以发现响应为空,异常消息是“远程服务器返回错误:(403)禁止.”
请帮我解决一下这个. Msdn不提供此示例:( using System; using System.Collections.Generic; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Xml; using System.Xml.Linq; class ManagemenCertificateViewer { public static void Runme() { string msVersion = "2012-03-01"; string subscriptionId = "I used the subscription Id here"; try { ListManagementCertificates(subscriptionId,msVersion); } catch (Exception ex) { Console.WriteLine("Exception caught: "); Console.WriteLine(ex.Message); } } private static void ListManagementCertificates(string subscriptionId,string version) { string uriFormat = "https://management.core.windows.net/{0}/certificates"; Uri uri = new Uri(string.Format(uriFormat,subscriptionId)); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); request.Method = "GET"; request.Headers.Add("x-ms-version",version); request.ContentType = "application/xml"; XDocument responseBody = null; HttpStatusCode statusCode; HttpWebResponse response; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { // GetResponse throws a WebException for 400 and 500 status codes response = (HttpWebResponse)ex.Response; } statusCode = response.StatusCode; if (response.ContentLength > 0) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { responseBody = XDocument.Load(reader); } } response.Close(); if (statusCode.Equals(HttpStatusCode.OK)) { XNamespace wa = "http://schemas.microsoft.com/windowsazure"; XElement storageServices = responseBody.Element(wa + "SubscriptionCertificates"); int mngmntCertificateCount = 0; foreach (XElement storageService in storageServices.Elements(wa + "SubscriptionCertificate")) { string publicKey = storageService.Element(wa + "SubscriptionCertificatePublicKey").Value; string thumbprint = storageService.Element(wa + "SubscriptionCertificateThumbprint").Value; string certificateData = storageService.Element(wa + "SubscriptionCertificateData").Value; string timeCreated = storageService.Element(wa + "TimeCreated").Value; Console.WriteLine( "Certificate[{0}]{1} SubscriptionCertificatePublicKey: {2}{1} SubscriptionCertificateThumbprint: {3}{1} certificateData{4}{1} timeCreated{5}{1}",mngmntCertificateCount++,Environment.NewLine,publicKey,thumbprint,certificateData,timeCreated); } } else { Console.WriteLine("List Management certificates returned an error:"); Console.WriteLine("Status Code: {0} ({1}):{2}{3}",(int)statusCode,statusCode,responseBody.ToString(SaveOptions.OmitDuplicateNamespaces)); } return; } } 解决方法
403错误表示用于验证Service Management API请求的管理证书有问题.我没有看到您在代码中附上管理证书以及您的请求.您可能会发现此链接对于验证服务管理API请求非常有用:
http://msdn.microsoft.com/en-us/library/windowsazure/ee460782.
HTH. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – 系统进程中的无效句柄太多
- 如何在启动时测量Windows服务的启动时间和顺序?
- AWS Athena 分析日志
- SysPrep Windows 10 Pro错误(0x0f0070和0x0f00d8)
- windows – 如何使Process Explorer的功能“替换任务管理器
- windows-server-2003 – 将共享文件夹和用户配置文件夹移动
- 后台进程 – BITS仍然是一个很好的后台更新技术吗?
- win10 uwp 使用 msbuild 命令行编译 UWP 程序
- windows-server-2008 – Subversion Edge LDAP(需要CAC证书
- 适用于Skype的Android Api?
推荐文章
站长推荐
- windows – 正在等待虚假唤醒的事件?
- 需要在Windows / Python中快速创建大量新进程
- [转帖]Ansible批量远程管理Windows主机(部署与配
- R Performance Differential(Solaris vs Windows
- 防病毒 – Windows Defender和Microsoft Windows
- 如何更改WinRT WebView的缩放级别?
- 图像处理---《在图片上打印文字 windows+GDI+Tru
- Windows – 如何使用批处理脚本从.properties文件
- windows-server-2003 – WMI会导致CPU蠕变吗?
- rest – Microsoft Graph API选择并过滤日历中的
热点阅读