PayPal API, HttpWebRequest throws SSL WebException

I'm trying to get a PayPal access token, as shown here: https://developer.paypal.com/docs/integration/direct/make-your-first-call/#get-an-access-token

My C # code is as follows:

    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();

When calling request.GetRequestStream (), I get a WebException with the German text "Die Anfrage wurde abgebrochen: Es konnte kein geschรผtzter SSL / TLS-Kanal erstellt werden". which means that he was unable to create a secure SSL / TLS channel.

How am I wrong? Can anybody help me?

Thanks Volker

+4
source share
2 answers

I found a solution:

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

Maybe this helps someone else ...

+5

, SSL 3, .

TLS 1.1 1.2

ServicePointManager.SecurityProtocol =  SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
+2

Source: https://habr.com/ru/post/1667284/


All Articles