簡體   English   中英

Restsharp請求到Stripe給SendFailure錯誤

[英]Restsharp request to Stripe give SendFailure error

我嘗試使用RestSharp將請求發送到Stripe API 我建立了請求,但是由於身份驗證錯誤而無法發送。 該請求返回0錯誤代碼。

這是我的代碼:

    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

正如我在評論中所說,我使用Unity 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;
}

所有證書都將被驗證,因此請小心...就我而言,我與Stripe API通信,因此我認為還可以! ;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM