我必须在 Paypal 中使用 SSL 吗?如何在 Windows Azure 上设置 Paypal?

Do I have to use SSL with Paypal? How do I set Paypal on Windows Azure?

我正在将我 3 年前 运行 拥有的旧 Web 应用程序上线。 当时一切正常,Paypal 的 ExpressCheckout 设置完美。

我真的不记得我当时在做什么,但现在我把我的应用放在 Windows Azure 上了。我的应用程序是用 ASP.NET MVC5 编写的。

对于那些在您的应用程序中实现了 Paypal 的人来说,下面这段代码可能看起来很熟悉,它可能取自 Paypal 的文档并用于向 Paypal 的服务器发送消息:

    /// <summary>
    /// HttpCall: The main method that is used for all API calls
    /// </summary>
    /// <param name="NvpRequest"></param>
    /// <returns></returns>
    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;
        objRequest.ContentType = "application/x-www-form-urlencoded";

        try
        {
            using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
            {
                myWriter.Write(strPost, 0, strPost.Length);
            }
        }
        catch (Exception e)
        {
            CommonFuncs.Log(MyGlobals.LOG_FILE_DO_EXPRESS_CHECKOUT, e.Message);
            return null;
            /*
            if (log.IsFatalEnabled)
            {
                log.Fatal(e.Message, this);
            }*/
        }


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

        //Logging the response of the transaction
        /* if (log.IsInfoEnabled)
         {
             log.Info("Result :" +
                       " Elapsed Time : " + (DateTime.Now - startDate).Milliseconds + " ms" +
                      result);
         }
         */
        return result;
    }

现在,当我尝试 POST(此处)

using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
                {
                    myWriter.Write(strPost, 0, strPost.Length);
                }

我收到以下错误消息

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

这是否意味着我必须购买 SSL 证书?或者有什么我只需要在 Azure 上调整一下就可以使用的东西吗?

无需购买 SSL。但您可以将证书升级为 SHA 256 和 TLS 1.2。参考下面的link。

https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1913

https://github.com/paypal/TLS-update

谢谢@PP_MTS_Steven。 我不记得给了我解决方案的 SO 来源。然而,我所做的只是把这两行代码:

        ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
        // allows for validation of SSL conversations
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

就在这里:

    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);
        ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
        // allows for validation of SSL conversations
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };


        HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
        objRequest.Timeout = Timeout;
        objRequest.Method = "POST";
        objRequest.ContentLength = strPost.Length;
        objRequest.ContentType = "application/x-www-form-urlencoded";
        ...

事情开始奏效了。