相关疑难解决方法(0)

请求已中止:无法创建SSL/TLS安全通道

WebRequest由于此错误消息,我们无法连接到HTTPS服务器:

The request was aborted: Could not create SSL/TLS secure channel.

我们知道服务器没有使用路径的有效HTTPS证书,但是为了绕过这个问题,我们使用以下代码,我们从另一个StackOverflow帖子中获取:

private void Somewhere() {
    ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCertificate);
}

private static bool AlwaysGoodCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors) {
   return true;
}
Run Code Online (Sandbox Code Playgroud)

问题是服务器永远不会验证证书并因上述错误而失败.有谁知道我该怎么办?


我应该提到一位同事和我几周前进行了测试,并且它与我上面写的内容类似.我们发现的唯一"主要差异"是我使用的是Windows 7并且他使用的是Windows XP.这有什么改变吗?

c# asp.net httpwebrequest windows-7 windows-8

349
推荐指数
29
解决办法
63万
查看次数

请求已中止:无法创建SSL/TLS安全通道沙箱帐户

它在一周之前运作良好,但现在它显示以下错误.我尝试过以下的东西,但没有用.

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
Run Code Online (Sandbox Code Playgroud)

所以建议我可能的解决方案

public string HttpCall(string NvpRequest) //CallNvpServer
    {
        string url = pendpointurl;

        //To Add the credentials from the profile
        string strPost = NvpRequest + "&" + buildCredentialsNVPString();
        strPost = strPost + "&BUTTONSOURCE=" + HttpUtility.UrlEncode(BNCode);

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
        // allows for validation of SSL conversations
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };


        HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
        objRequest.Timeout = Timeout;
        objRequest.Method = "POST";
        objRequest.ContentLength = strPost.Length;

        try
        {
            using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
            {
                myWriter.Write(strPost); …
Run Code Online (Sandbox Code Playgroud)

.net paypal sandbox

36
推荐指数
3
解决办法
5万
查看次数

标签 统计

.net ×1

asp.net ×1

c# ×1

httpwebrequest ×1

paypal ×1

sandbox ×1

windows-7 ×1

windows-8 ×1