Wil*_*ngs 4 c# asp.net ssl paypal httpwebrequest
我正在制作一个asp.net网络表单应用程序,它提供使用paypal支付.该应用程序应该使用ssl.当我运行我的应用程序一切顺利,直到我选择我的按钮paypal支付.当我按下此按钮时,会出现以下错误:
请求已中止:无法创建SSL/TLS安全通道.
描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.Net.WebException:请求已中止:无法创建SSL/TLS安全通道.
来源错误:
第203行:第204行://检索从对PayPal的NVP API调用返回的响应.第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
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;
}
Run Code Online (Sandbox Code Playgroud)
您的代码段未指定要使用的安全协议 - 我可以告诉您 -
例:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Run Code Online (Sandbox Code Playgroud)
我在针对paypal api查看不同的身份验证方法后发现了这一点.
这里有一个相关的话题值得信赖.问题与-贝宝API-HTTP调用
注意:在原始OP问题的一系列评论之后添加了这个答案.
| 归档时间: |
|
| 查看次数: |
10369 次 |
| 最近记录: |