5
votes

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);

Thanks.

1

1 Answers

5
votes

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) 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)

The certs[0] will have the certificate

4) To attach the certificate to HTTP request

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

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