gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:30:29 26 4
gpt4 key购买 nike

我正在制作一个提供使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com