【问题标题】:HttpWebRequest: The request was aborted: Could not create SSL/TLS secure channelHttpWebRequest:请求被中止:无法创建 SSL/TLS 安全通道
【发布时间】:2016-06-30 14:25:06
【问题描述】:

我正在制作一个 asp.net 网络表单应用程序,它提供使用贝宝付款。该应用程序应该使用 ssl。当我运行我的应用程序时一切顺利,直到我选择我的按钮通过贝宝付款。当我按下此按钮时,会出现以下错误:

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

描述:执行过程中发生了未处理的异常 当前的网络请求。请查看堆栈跟踪以获取更多信息 有关错误的信息以及它在代码中的来源。

异常详细信息:System.Net.WebException:请求被中止: 无法创建 SSL/TLS 安全通道。

来源错误:

Line 203: Line 204: //检索从 NVP API 调用 PayPal。第 205 行:HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();第 206 行:字符串 结果;第 207 行:使用 (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))

源文件:C:\Users\willem\documents\visual studio 2015\Projects\WingtipToys\WingtipToys\Logic\PayPalFunctions.cs
线路: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;
}

【问题讨论】:

  • 您是否安装了调用端点所需的 SSL 证书?
  • 当 Windows 询问我时,我相信我做到了:您愿意信任 IIS Express SSL 证书并继续吗?然后:你想安装这个证书吗?我都回答是的。
  • 我指的是您尝试为其创建 Web 请求的端点。当您使用浏览器浏览该服务端点时,它是否会为您提供已在您的工作站上本地安装/信任的证书?
  • 当我将 url 复制到浏览器时,我收到以下消息:ACK=Failure&L_ERRORCODE0=81002&L_SHORTMESSAGE0=Unspecified%20Method&L_LONGMESSAGE0=Method%20Specified%20is%20not%20Supported&L_SEVERITYCODE0=Error 这是您的问题的答案?我以前从未使用过 ssl,所以如果我不清楚,我很抱歉
  • 您的代码 sn-p 没有根据我的判断指定要使用的安全协议 - 例如:ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;这里有一个相关的话题,我想你也需要看看problems-with-paypal-api-http-call

标签: c# asp.net ssl paypal httpwebrequest


【解决方案1】:

据我所知,您的代码 sn-p 没有指定要使用的安全协议 -

例子:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

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

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

注意:此答案是在原始 OP 问题的 cmets 字符串之后添加的。

【讨论】:

    猜你喜欢
    • 2017-12-10
    • 2020-09-23
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 2018-04-22
    相关资源
    最近更新 更多