客户端证书 Windows Phone 8.1 [英] Client Certificates Windows Phone 8.1

查看:34
本文介绍了客户端证书 Windows Phone 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows Phone 8.1 是否支持向 HTTP Web 请求添加客户端证书?我正在尝试执行与以下类似的操作,但我似乎无法确定在 WP8.1 上什么(如果有)与此等效:

Does Windows Phone 8.1 support adding a client certificate to an HTTP web request? I'm trying to do something similar to the following, but I can't seem to determine what (if any) is the equivalent to this on WP8.1:

System.Net.HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.ClientCertificates.Add(certificate);

谢谢.

推荐答案

我假设您已经将客户端证书放在应用程序证书存储中.如果不是这就是你必须这样做的方式1) 下载 PFX 文件.2) 使用以下方式将其安装在应用程序的证书库中

I assume that you have already put the client certificate in app certificate store. If not this is how you will have to do that 1) Download the PFX file. 2) Install it in the App's certificate store using the following way

await CertificateEnrollmentManager.ImportPfxDataAsync(certString, "Your_PFX_Password", ExportOption.Exportable, KeyProtectionLevel.NoConsent, InstallOptions.None, friendlyName);

3) 下一步是在证书存储中查找证书.这是按如下方式完成的

3) The next step is to look for the certificate in certificate store. This is done as below

CertificateQuery certQuery = new CertificateQuery();
certQuery.FriendlyName = friendlyName;
IReadOnlyList<Certificate> certs = await CertificateStores.FindAllAsync(certQuery)

certs[0] 将拥有证书

The certs[0] will have the certificate

4) 将证书附加到 HTTP 请求中

4) To attach the certificate to HTTP request

HttpBaseProtocolFilter protolFilter = new HttpBaseProtocolFilter();
protolFilter.ClientCertificate = certs[0] //from previous step
HttpClient client = new HttpClient(protolFilter)

需要注意的是你不应该使用 System.Net.htpp.HttpClient.相反,您应该使用 Windows.Web.Http.HttpClient.

Point to note is you should not use System.Net.htpp.HttpClient. Instead you should you Windows.Web.Http.HttpClient.

这篇关于客户端证书 Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆