对 Stripe 的 Restsharp 请求给出 SendFailure 错误

Restsharp request to Stripe give SendFailure error

我尝试使用RestSharp to send request to the Stripe API。我构建了我的请求,但由于身份验证错误而无法发送。请求 return 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

正如我在评论中所说,我在使用 .NET 2.0 的 Unity 5.3 上工作。此版本的 .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 通信,所以我认为没问题! ;)