相关疑难解决方法(0)

允许使用HttpClient的不受信任的SSL证书

我很难让我的Windows 8应用程序通过SSL与我的测试Web API进行通信.

似乎HttpClient/HttpClientHandler没有提供和选项来忽略WebRequest之类的不受信任的证书使你(尽管以"hacky"方式ServerCertificateValidationCallback).

任何帮助将非常感激!

.net c# windows-8 windows-runtime

95
推荐指数
10
解决办法
12万
查看次数

Xamarin WKWebView接受自签名证书

我在网上看到各种示例,说出如何接受它们,但我总是收到SSL错误,并且无法建立与服务器的安全连接。

我会注意到,该方法肯定是被调用的(在iOS 8.4模拟器和iOS 11实际设备上运行),因此未调用该方法不是这里的问题。

到目前为止,我已经尝试过(显然,我仅在开发中而不是在生产中使用此代码,等等等等):

1:

public override void DidReceiveAuthenticationChallenge(WKWebView webView, NSUrlAuthenticationChallenge challenge, Action<NSUrlSessionAuthChallengeDisposition, NSUrlCredential> completionHandler) {
 completionHandler(NSUrlSessionAuthChallengeDisposition.UseCredential, new NSUrlCredential(serverTrust));
}
Run Code Online (Sandbox Code Playgroud)

2:

public override void DidReceiveAuthenticationChallenge(WKWebView webView, NSUrlAuthenticationChallenge challenge, Action<NSUrlSessionAuthChallengeDisposition, NSUrlCredential> completionHandler) {
 completionHandler(NSUrlSessionAuthChallengeDisposition.UseCredential, NSUrlCredential.FromTrust(serverTrust));
}
Run Code Online (Sandbox Code Playgroud)

3:

    public override void DidReceiveAuthenticationChallenge(WKWebView webView, NSUrlAuthenticationChallenge challenge, Action<NSUrlSessionAuthChallengeDisposition, NSUrlCredential> completionHandler) {
        SecTrust serverTrust = challenge.ProtectionSpace.ServerSecTrust;
        NSData exceptions = serverTrust.GetExceptions();
        serverTrust.SetExceptions(exceptions);
        exceptions.Dispose();
        completionHandler(NSUrlSessionAuthChallengeDisposition.UseCredential, NSUrlCredential.FromTrust(serverTrust));
    }
Run Code Online (Sandbox Code Playgroud)

4:

    public override void DidReceiveAuthenticationChallenge(WKWebView webView, NSUrlAuthenticationChallenge challenge, Action<NSUrlSessionAuthChallengeDisposition, NSUrlCredential> completionHandler) {
        SecTrust serverTrust = challenge.ProtectionSpace.ServerSecTrust;    //TODO: Get …
Run Code Online (Sandbox Code Playgroud)

webview xamarin.ios xamarin wkwebview

1
推荐指数
1
解决办法
1214
查看次数