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

标签 c# asp.net ssl paypal httpwebrequest

我正在制作一个提供使用 paypal 付款的 asp.net web 表单应用程序。该应用程序应该使用 ssl。当我运行我的应用程序时,一切顺利,直到我选择我的 Paypal 支付按钮。当我按下此按钮时,出现以下错误:

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

Source Error:

Line 203: Line 204: //Retrieve the Response returned from the NVP API call to PayPal. Line 205: HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); Line 206: string result; Line 207: using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))

Source File: C:\Users\willem\documents\visual studio 2015\Projects\WingtipToys\WingtipToys\Logic\PayPalFunctions.cs
Line: 205

下面我的错误发生的方法

public string HttpCall(string NvpRequest)
{
    string url = pEndPointURL;

    string strPost = NvpRequest + "&" + buildCredentialsNVPString();
    strPost = strPost + "&BUTTONSOURCE=" + HttpUtility.UrlEncode(BNCode);

    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);
        }
    }
    catch (Exception)
    {
        // No logging for this tutorial.
    }

    //Retrieve the Response returned from the NVP API call to PayPal.
    HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
    string result;
    using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
    {
        result = sr.ReadToEnd();
    }

    return result;
}

最佳答案

据我所知,您的代码片段未指定要使用的安全协议(protocol) -

示例:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

我在查看针对 paypal api 的不同身份验证方法后发现了这一点。

这里有一个相关的主题值得称赞。 problems-with-paypal-api-http-call

注意:这个答案是在对原始 OP 问题的评论字符串之后添加的。

关于c# - HttpWebRequest:请求已中止:无法创建 SSL/TLS 安全通道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36006333/

相关文章:

c# - 如何增加命名管道的MaxStringContentLength?

c# - ASP.net MVC 4 - CaSTLe Windsor - 找不到方法 : 'System. Web.Http.Services.DependencyResolver

java - 部署 Java 应用程序时处理安全性

c# - 仅在 .Net 中证书身份验证失败并出现 SSL 错误

c# - .net MemoryCache - 通知删除的项目

c# - 在 Azure 移动服务中找不到属性 nameId

asp.net - 使用 Microsoft 客户端 AJAX 库从一个文本框跳转到另一个文本框的最佳方法是什么?

asp.net - DropDownList RequiredFieldValidator 不工作

java - Android HttpClient - 证书中的主机名不匹配 <example.com> != <*.example.com>

c# - 无法使用 asp.net 和 CSS (C#) 居中图像