所以我正在测试通用应用程序并达到了这一点:
我在 Windows 平板电脑上有一个从服务器获取数据的应用程序。
服务器受证书保护( SSL )
我有这段代码,在简单的 Windows Store 应用程序和平板电脑通用应用程序项目上运行良好,但在手机上运行良好
async public static Task<string> GetDataFromServer()
{
try
{
HttpClientHandler aHandler = new HttpClientHandler();
aHandler.ClientCertificateOptions = ClientCertificateOption.Automatic;
HttpClient aClient = new HttpClient(aHandler);
aClient.DefaultRequestHeaders.ExpectContinue = false;
aClient.DefaultRequestHeaders.MaxForwards = 3;
Uri requestUri = new Uri("MYURL");
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
var result = await aClient.GetAsync(requestUri, HttpCompletionOption.ResponseContentRead);
var responseHeader = result.Headers;
var responseBody = await result.Content.ReadAsStringAsync();
return responseBody;
}
catch (Exception e)
{
return "";
}
}
所有需要的功能都在清单中设置:
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="sharedUserCertificates" />
<Capability Name="privateNetworkClientServer" />
<Capability Name="internetClientServer" />
</Capabilities>
<Extensions>
<Extension Category="windows.certificates">
<Certificates>
<Certificate StoreName="Root" Content="Assets\CoolCertificate.cer" />
</Certificates>
</Extension>
电话代码 - 不会崩溃,没有错误或警告 - 只是空白结果。
代码: {StatusCode:404,ReasonPhrase:'未找到',版本:1.1,内容:System.Net.Http.StreamContent,标题:{ Content-Length:0}} 并且没有像 WinRT 中那样通知用户: