简体   繁体   English

C#/ UWP:如何使用HttpClient管理证书错误?

[英]C#/UWP : How to manage certificate errors with HttpClient?

I've developed an UWP app for a client , which uses WebServices that are hosted in its domain . 我为客户端开发了UWP应用 ,该应用使用在其域中托管的WebService

  • Until now, the URL WebServices were related to a test server that don't use SSL 到目前为止,URL WebServices与未使用SSL的测试服务器相关

  • But now, the WebServices URL are related to the prod server that use SSL 但是现在,WebServices URL与使用SSL产品服务器相关

As I'm a subcontractor, I don't have an AD account, and I need to use the VPN to access to the client's WebServices. 因为我是分包商,所以没有AD帐户,我需要使用VPN来访问客户端的WebServices。

I didn't get any problem to access to the test server, but it's no longer the case with the prod server. 访问测试服务器没有任何问题,但生产服务器不再是这种情况。

When I try to access to access to the URL through a navigator, I get a security warning message ( DLG_FLAGS_INVALID_CA ), but I can "force" the navigation to the URL. 当我尝试通过导航器访问URL时,会收到一条安全警告消息( DLG_FLAGS_INVALID_CA ),但是我可以“强制”导航到URL。

But when I call the WebService from the app with HttpCLient , I also get an error ( HttpRequestException ) and I don't see how I could fix it. 但是,当我使用HttpCLient从应用程序调用WebService时,我也收到一个错误( HttpRequestException ),但看不到如何解决它。

Here are the details of the exception: 以下是例外的详细信息:

HResult = -2147012851 HResult = -2147012851

InnerException = {System.Runtime.InteropServices.COMException (0x80072F0D): Can't find text related to the error code. InnerException = {System.Runtime.InteropServices.COMException(0x80072F0D):找不到与错误代码相关的文本。 The certificate authority is invalid or is incorrect at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) ... 证书颁发机构在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)处无效或不正确...

Message = "An error occurred while sending the request." Message =“发送请求时发生错误。”

Source = "System.Net.Http" 来源=“ System.Net.Http”

I've already tried to install handly the certificates on my computer, but this doesn't fix the issue... 我已经尝试在计算机上手动安装证书,但这不能解决问题。

Is there another approach? 还有其他方法吗?

Edit: add "user" certificate 编辑:添加“用户”证书

The client sent me the "user" certificate and I installed it on my computer in "User\\Trusted Root Certification Authorities Certificate Store" : there is no longer problem from the navigator. 客户端向我发送了“用户”证书,并将其安装在计算机上的“用户\\受信任的根证书颁发机构证书存储”中 :导航器不再存在问题。 However, in the app, the problem is still present. 但是,在应用程序中,问题仍然存在。

Is it normal? 正常吗 Do I need to "attach" the certificate to the app? 我需要将证书“附加”到应用程序吗? This is not really usefull, as the client's users don't need this problem: it's only me as I'm a subcontractor using the VPN... 这并不是真正有用的,因为客户端的用户不需要这个问题:因为我是使用VPN的分包商,所以只有我一个人...

Edit: add "computer" certificate 编辑:添加“计算机”证书

Finally the client sent me the "computer" certificate and I installed it on my computer in "Computer\\Trusted Root Certification Authorities Certificate Store" : this time I could use the app without problem. 最终,客户端向我发送了“计算机”证书,然后将其安装在计算机上的“计算机\\受信任的根证书颁发机构证书存储”中 :这次我可以毫无问题地使用该应用程序了。

It's good to know that the UWP app and the navigators don't use the same certificate. 很高兴知道UWP应用和导航器没有使用相同的证书。

通过安装客户端发送的“用户”“计算机”证书已解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM