HttpWebRequest:请求已中止:无法创建 SSL/TLS 安全通道
HttpWebRequest: The request was aborted: Could not create SSL/TLS secure channel
我正在制作一个 asp.net 网络表单应用程序,该应用程序提供使用 paypal 进行支付的功能。该应用程序应该使用 ssl。当我 运行 我的应用程序一切顺利,直到我 select 我的按钮通过 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;
}
据我所知,您的代码片段未指定要使用的安全协议 -
示例:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
我在查看针对 paypal 的不同身份验证方法后发现了这个 api。
这里有一个相关的话题值得借鉴。
注意:此答案添加在对原始 OP 问题的评论字符串之后。
我正在制作一个 asp.net 网络表单应用程序,该应用程序提供使用 paypal 进行支付的功能。该应用程序应该使用 ssl。当我 运行 我的应用程序一切顺利,直到我 select 我的按钮通过 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;
}
据我所知,您的代码片段未指定要使用的安全协议 -
示例:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
我在查看针对 paypal 的不同身份验证方法后发现了这个 api。
这里有一个相关的话题值得借鉴。
注意:此答案添加在对原始 OP 问题的评论字符串之后。