2016-06-16 25 views
0

我嘗試使用RestSharp發送請求到Stripe API。我構建了我的請求,但由於驗證錯誤而無法發送。該請求返回0錯誤代碼。Repsharp請求條帶給SendFailure錯誤

這裏是我的代碼:

var client = new RestClient("https://api.stripe.com"); 
    client.Authenticator = new HttpBasicAuthenticator (stripe_key, ""); 

    var request = new RestRequest("v1/tokens", Method.POST); 
    request.AddParameter("card[number]", card.number); 
    request.AddParameter("card[exp_month]", card.expMonth); 
    request.AddParameter("card[exp_year]", card.expYear); 
    request.AddParameter("card[cvc]", card.cvc); 

    IRestResponse response = client.Execute(request); 

    Log.trace ("Content : " + response.Content); 
    Log.trace ("Status code : " + response.StatusCode.ToString()); 
    Log.trace ("Error message : " + response.ErrorMessage); 

而且我的輸出:

Content : 
Status code : 0 
Error message : Error getting response stream (Write: The authentication or decryption has failed.): SendFailure 
+0

難道你不可能使用[Stripe.net](https://github.com/jaymedavis/stripe.net)? – Ywain

+0

不,我在Unity上工作,只支持.Net 2.0 ... –

+0

啊,那太糟糕了。 根據錯誤消息,問題似乎是您的系統無法連接到「https:// api.stripe.com」,因爲它無法驗證由Stripe的API服務器發送的SSL證書。如果可以,請嘗試導入此證書包(從官方的Stripe Ruby綁定中):https://raw.githubusercontent.com/stripe/stripe-ruby/master/lib/data/ca-certificates.crt – Ywain

回答

0

正如我在評論中說,我對統一5.3,它使用.NET 2.0。這個版本的.NET似乎很難驗證SSL證書。這個問題禁止SSL連接,這就是爲什麼我有一個「0」響應狀態。要覆蓋此確認,我這樣做:

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); 

public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) 
{ 
    return true; 
} 

所有證書將被驗證,所以一定要小心......就我而言,我與條紋API通信,以便在我看來,這是確定! ;)

+0

您可能想要檢查這是否符合PCI規範,我的猜測是它可能不是。 –