当前位置:  开发笔记 > 编程语言 > 正文

PayPal API,HttpWebRequest抛出SSL WebException

如何解决《PayPalAPI,HttpWebRequest抛出SSLWebException》经验,为你挑选了1个好方法。

我正在尝试获取PayPal访问令牌,如下所示:https: //developer.paypal.com/docs/integration/direct/make-your-first-call/#get-an-access-token

我的C#代码如下所示:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.sandbox.paypal.com/v1/oauth2/token");
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(clientId + ":" + clientSecret));
request.Accept = "application/json";
request.Headers.Add("Accept-Language", "en_US");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = 10000;

byte[] postBytes = Encoding.ASCII.GetBytes("grant_type=client_credentials");
request.ContentLength = postBytes.Length;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

Stream postStream = request.GetRequestStream(); // ###### Here I get the Exception! ######
postStream.Write(postBytes, 0, postBytes.Length);
postStream.Flush();
postStream.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

当调用request.GetRequestStream()时,我得到了一个带有德语文本的WebException"Die Anfrage wurde abgebrochen:Es konntekeingeschützterSSL/ TLS-Kanal erstellt werden." 这意味着它无法创建安全的SSL/TLS通道.

我做错了什么?有谁能够帮我?

谢谢,Volker



1> Volker..:

我找到了解决方案:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; //SecurityProtocolType.Tls12;

也许它也有助于其他人......

推荐阅读
凹凸曼00威威_694
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有