简体   繁体   中英

HttpWebRequest: The request was aborted: Could not create SSL/TLS secure channel

I'm making a asp.net web forms application which offers to pay using paypal. The application is supposed to make use of ssl. When i run my application all goes well until i select my button pay by paypal. When i press this button the following error occurs:

The request was aborted: Could not create SSL/TLS secure channel.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

Source Error:

Line 203: Line 204: //Retrieve the Response returned from the NVP API call to PayPal. Line 205: HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); Line 206: string result; Line 207: using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))

Source File: C:\\Users\\willem\\documents\\visual studio 2015\\Projects\\WingtipToys\\WingtipToys\\Logic\\PayPalFunctions.cs
Line: 205

Below my method in which the error ocurs

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;
}

Your code snippet does not specify the security protocol to use from what I can tell -

Example:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

I found this after looking at different authentication methods against the paypal api.

There is a related topic here that deserves the credit. problems-with-paypal-api-http-call

Note: This answer was added after the string of comments on the original OP question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM