加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 23:31:40 所属栏目:百科 来源:网络整理
导读:我正在制作一个asp.net网络表单应用程序,它提供使用paypal支付.该应用程序应该使用ssl.当我运行我的应用程序一切顺利,直到我选择我的按钮paypal支付.当我按下此按钮时,会出现以下错误: The request was aborted: Could not create SSL/TLS secure channel.
我正在制作一个asp.net网络表单应用程序,它提供使用paypal支付.该应用程序应该使用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:Userswillemdocumentsvisual studio
2015ProjectsWingtipToysWingtipToysLogicPayPalFunctions.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;
}

解决方法

您的代码段未指定要使用的安全协议 – 我可以告诉您 –

例:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

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

这里有一个相关的话题值得信赖. problems-with-paypal-api-http-call

注意:在原始OP问题的一系列评论之后添加了这个答案.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读