首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SSL,HttpWebRequest抛出PayPal WebException

SSL,HttpWebRequest抛出PayPal WebException
EN

Stack Overflow用户
提问于 2017-01-20 02:18:13
回答 2查看 2.6K关注 0票数 5

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

我的C#代码如下所示:

代码语言:javascript
复制
    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()时,我得到一个德语文本为"Die Anfrage wurde abgebrochen: Es konnte kein geschützter SSL/TLS-Kanal erstellt werden“的WebException。这意味着它无法创建安全的SSL/TLS通道。

我做错了什么?有人能帮我吗?

谢谢,沃克

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-01-20 16:23:19

我找到了解决方案:

代码语言:javascript
复制
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; //SecurityProtocolType.Tls12;

也许这对其他人也有帮助。

票数 5
EN

Stack Overflow用户

发布于 2017-01-24 01:51:18

正确的,他们不再使用SSL3,这就是错误的来源。

您可以使用TLS 1.1和1.2

代码语言:javascript
复制
ServicePointManager.SecurityProtocol =  SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41748946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档