LMS
LMS

Reputation: 43

Could not create SSL/TLS secure channel - GetRequestStream()

I am trying to integrate paypal into a web application and I've not been successful. I have tried loads of things but I keep coming back to one particular error. I am now trying to use the paypal integration wizard, and when I get the code that is provided, I get an error that says: The request was aborted: Could not create SSL/TLS secure channel.

This is the code:

public string HttpCall(string NvpRequest) //CallNvpServer
{
    string url = pendpointurl;

    //To Add the credentials from the profile
    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;
    StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream());

The error occurs on the last line, on the objRequest.GetRequestStream()

I tried looking it up on google but I didn't find anything that worked for me. Does anybody know what I can do to fix this?

Upvotes: 3

Views: 3858

Answers (2)

Rick
Rick

Reputation: 1

I am here with the exact same problem on a different site, but for me this did not work, but the following did:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

Upvotes: 0

Kevin Farrugia
Kevin Farrugia

Reputation: 7489

Add the following code to your global.asax.cs Application_Started method or before calling the (HttpWebRequest)WebRequest.Create(url);

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

This was caused because PayPal are changing their encryption to TLS instead of SSL. This has already been updated on the Sandbox environments but not yet on the live.

Read more: https://devblog.paypal.com/upcoming-security-changes-notice/

Upvotes: 5

Related Questions