相关疑难解决方法(0)

C#忽略证书错误?

在对远程Web服务的Web服务请求期间,我收到以下错误:

无法为SSL/TLS安全通道建立信任关系.---> System.Security.Authentication.AuthenticationException:根据验证程序,远程证书无效.

反正有没有忽略这个错误,并继续?

似乎远程证书没有签名.

我连接的网站是www.czebox.cz- 所以随时访问该网站,并注意甚至浏览器抛出安全例外.

.net c# ssl

147
推荐指数
8
解决办法
18万
查看次数

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

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

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

任何帮助将非常感激!

.net c# windows-8 windows-runtime

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

Xamarin Android 问题通过 HTTPS 连接到使用自签名证书的站点:“未找到证书路径的信任锚。”

我正在尝试对具有 2 个 SSL 证书的站点进行 HTTPS 调用:一个自签名证书和一个由第一个证书签名的证书。当我使用 HttpClient 向站点发送请求时,控制台会记录一个不受信任的链,显示两个证书,然后打印由java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

我已经在我的手机上安装了这两个证书,并且将 Chrome 导航到该站点显示一个受信任的连接(在我安装证书之前它有一个不受信任的连接警告)。我认为问题在于该应用程序拒绝信任自签名证书。我无权访问服务器,因此对其证书没有影响,因此安装由受信任的 CA 签名的证书是不可行的。


我尝试过但没有奏效的解决方案。

ServicePointManager.ServerCertificateValidationCallback 似乎没有运行。

我曾尝试将自己的函数用于ServicePointManager.ServerCertificateValidationCallback,但我给它的委托似乎从未运行过。我的 MainActivity.OnCreate 方法中有以下代码,但控制台从不记录消息:

System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
{
  Console.WriteLine($"****************************************************************************************************");

  return true;
};
Run Code Online (Sandbox Code Playgroud)

HttpClientHandler.ServerCertificateCustomValidationCallback 引发异常。

我曾尝试使用 anHttpClientHandler并设置 its ServerCertificateCustomValidationCallback,但我只收到消息:

System.NotImplementedException: The method or operation is not implemented. at System.Net.Http.HttpClientHandler.set_ServerCertificateCustomValidationCallback (System.Func`5[T1,T2,T3,T4,TResult] value).

设置代码:

HttpClientHandler handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
HttpClient …
Run Code Online (Sandbox Code Playgroud)

ssl android httpclient xamarin

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

"错误:SendFailure(编写标题时出错)"

我正在尝试使用"rest sharp"软件包在"xamarin studio"中获取数据,如下所示:

var client = new RestClient ("https://xxxx.xxxx.com");

var request = new RestRequest ("/api/external/xxxx/xxxx/", Method.GET);
request.AddParameter("username", "xxxx");
request.AddParameter("api_key", "xxxx");

request.AddHeader("Content-type", "application/json");      
request.AddHeader("Accept", "text/plain");

request.RequestFormat = DataFormat.Json;

var response = client.Execute (request);

var model = JsonConvert.DeserializeObject<RootObject> (response.Content);
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

错误:SendFailure(写入标题时出错)

我真的不知道出了什么问题.我正在使用Windows 7 64位.

请帮忙...谢谢你提前!!!

c# android httpresponse restsharp xamarin

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

尽管 servicePointManager hack,WebRequest 无法在 Xamarin.Forms 上使用 ssl

我正在编写一个需要从 REST api 读取的应用程序,该 api 只能通过 https 使用。我遇到了 Mono.Security 中请求失败的问题,并显示消息:“身份验证或解密失败。”

我做了我的研究,发现 Mono 默认情况下没有任何受信任的证书。我找到的所有来源都说我可以使用

ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });

在 iOS 和 Droid 项目中的 Main() 和 OnCreate() 方法中分别覆盖该检查并允许任何 ssl 证书。即使采用这种解决方法,我仍然遇到相同的错误。我已经单步执行了代码,并确认在 iOS 和 Android 上运行时会执行上述行。

我的代码在访问非 https API 时完美运行。这是一个 PCL 项目,而非共享项目。

我在问之前提到了这些问题/资源:

  • 忽略 Xamarin.Forms (PCL) 中的 SSL 证书错误
  • stackoverflow.com/questions/2675133/c-sharp-ignore-certificate-errors/2675183#2675183
  • bugzilla.xamarin.com/show_bug.cgi?id=6501
  • stackoverflow.com/questions/12287528/webclient-ssl-exception-with-android-4-and-mono-for-android
  • www.mono-project.com/docs/faq/security/

这是到目前为止的代码:

public class PawPrintsDataConnection
{
    private string response = "";
    private Task<string> StartWebRequest(string url)
    {

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.ContentType = "application/json";
        request.Method …
Run Code Online (Sandbox Code Playgroud)

mono xamarin.ios xamarin.android xamarin xamarin.forms

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