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

孤者浪人 提交于 2019-12-22 09:05:11

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/36006333/httpwebrequest-the-request-was-aborted-could-not-create-ssl-tls-secure-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!