RestSharp和忽略SSL证书中的错误
我试图在显然没有有效ssl证书的服务器上使用RestSharp启动REST请求,因为我得到了错误 基础连接已关闭:无法建立信任 SSL/TLS安全通道的关系 我发现,但是提供的解决方案,尽管看起来很简单,却不起作用,我仍然会得到错误。这是我的代码,有什么想法吗RestSharp和忽略SSL证书中的错误,rest,ssl,restsharp,Rest,Ssl,Restsharp,我试图在显然没有有效ssl证书的服务器上使用RestSharp启动REST请求,因为我得到了错误 基础连接已关闭:无法建立信任 SSL/TLS安全通道的关系 我发现,但是提供的解决方案,尽管看起来很简单,却不起作用,我仍然会得到错误。这是我的代码,有什么想法吗 private void Test_REST() { var client = new RestClient("https://online.gema.de"); // both versions not working S
private void Test_REST()
{
var client = new RestClient("https://online.gema.de");
// both versions not working
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
client.RemoteCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
// execute the request
IRestResponse response = client.Execute(GEMA_Authorize());
var content = response.Content; // raw content as string
}
private RestRequest GEMA_Authorize()
{
RestRequest request = new RestRequest("api/v1/authorize", Method.GET);
request.AddParameter("response_type", "token");
request.AddParameter("client_id", "test_client");
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
return request;
}
当我这样编写回调时:
.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
{
return true;
};
并在返回true处设置断点代码>执行并没有停止,因此回调似乎从未被回调。你知道可能是什么问题吗?我对休息还比较陌生,所以我可能会错过一些重要的事情
提前感谢,
弗兰克的用法
client.RemoteCertificateValidationCallback=(发送方、证书、链、sslPolicyErrors)=>true;
为我工作。客户端回调不是一个事件处理程序,而是一个委托。当您需要使用=
时,为什么要给它们分配+=
?RestSharp没有SSL处理。它使用HttpWebRequest
,回调分配应该可以工作client.RemoteCertificateValidationCallback=(发送方、证书、链、sslPolicyErrors)=>true代码>应该没问题。嘿,亚历克赛,非常感谢你的回复。我使用+=是因为这是链接SO问题使用它的方式。我试过用你的建筑,仍然没有成功,错误依然存在。设置断点表明回调仍然没有被调用。FWIW,我遇到了这个问题,从回调名称中找到了这个Q,并使用了以下行:client.RemoteCertificateValidationCallback=(发送方、证书、链、错误)=>true;这对我来说“很有效”。所以我不能帮助解决这个问题,但也许可以帮助其他找到它的人。。。