HTTPS在C#中发布到证书错误的服务器-超时

HTTPS在C#中发布到证书错误的服务器-超时,c#,post,ssl,httpwebrequest,webclient,C#,Post,Ssl,Httpwebrequest,Webclient,我试图在C#中向未安装正确SSL证书的服务器(我的测试开发服务器)发送HTTPS帖子。请求正在使用WebClient和HttpWebRequest超时。我已经设置了自己的ServerCertificateValidationCallback以绕过证书检查,但这没有帮助。如果我在网页中进行完全相同的调用,则该调用将成功 因此: 我的WebClient帖子代码如下: private static bool AcceptAllCertifications(object sender, System.S

我试图在C#中向未安装正确SSL证书的服务器(我的测试开发服务器)发送HTTPS帖子。请求正在使用WebClient和HttpWebRequest超时。我已经设置了自己的ServerCertificateValidationCallback以绕过证书检查,但这没有帮助。如果我在网页中进行完全相同的调用,则该调用将成功

因此:

我的WebClient帖子代码如下:

private static bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
    //solve the problem of invalid certificates - accept all as valid
    return true;
}    

public void callPost(object o)
{
    string myData = (string)o;
    try
    {
        Uri uri = new Uri("https://testServer/myAction");
        WebClient client = new WebClient();
        client.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        byte[] uploadBytes = Encoding.UTF8.GetBytes(myData);
        ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
        byte[] responseBytes = client.UploadData(uri, "POST", Encoding.UTF8.GetBytes(urlData));
        Console.WriteLine("WebRequest:{0}\n", Encoding.ASCII.GetString(responseBytes));
    }
    catch (Exception e)
    {
        Console.WriteLine("WebRequest Error:{0}\n", e.ToString());
    }
}

有没有办法让这个职位在C#中工作?谢谢

经过更多的搜索,我发现有人遇到了类似的问题,并且找到了解决方案。 要调试此情况和类似情况,请按此处所述启用SSL跟踪/日志记录

我的问题是我需要声明一个SSL3连接,如下所示

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

在调用
客户端之前将此添加到我的代码中。UploadData
修复了此问题。

我认为您不能将测试/开发证书添加到计算机的本地证书存储中,使其不再无效?或者,如果您的帐户位于域上,请DC创建证书并将DC添加为本地证书颁发机构?@Kye是正确的。我尝试过一次,但在服务器中没有相应的权限。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;