2016-03-15 137 views
3

我正在製作一個asp.net網頁表單應用程序,該應用程序提供使用paypal付款。該應用程序應該使用ssl。當我運行我的應用程序一切順利,直到我選擇我的按鈕paypal支付。當我按下這個按鈕,會出現以下錯誤:HttpWebRequest:請求已中止:無法創建SSL/TLS安全通道

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

下面我的方法,其中錯誤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; 
} 
+0

您是否安裝了調用端點所需的SSL證書? – Elmar

+0

我相信我在Windows時問我:你想信任IIS Express SSL證書並繼續?然後:你想安裝這個證書嗎?我都回答是。 – WillemKoonings

+0

我指的是您嘗試創建Web請求的端點。當您使用瀏覽器瀏覽該服務端點時,是否會向您顯示您已在工作站上本地安裝/信任的證書? – Elmar

回答

7

您的代碼段未指定安全協議,從我可以告訴使用 -

例子:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 

我發現這個看不同AUT後針對paypal api的hentication方法。

這裏有一個相關的話題,值得信任。 problems-with-paypal-api-http-call

注意:這個答案是在對原始OP問題的評論串之後添加的。

相關問題