【问题标题】:Restsharp request to Stripe give SendFailure errorRestsharp 对 Stripe 的请求给出了 SendFailure 错误
【发布时间】:2016-10-17 19:35:30
【问题描述】:

我尝试使用RestSharpStripe 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

【问题讨论】:

  • 你不能用Stripe.net吗?
  • 不,我在 Unity 上工作,它只支持 .Net 2.0...
  • 啊,太糟糕了。根据错误信息,问题似乎是您的系统无法连接到https://api.stripe.com,因为它无法验证Stripe API 服务器发送的SSL 证书。如果可以,请尝试导入此证书包(来自官方 Stripe Ruby 绑定):raw.githubusercontent.com/stripe/stripe-ruby/master/lib/data/…
  • 我现在刚刚“解决”了我的问题!正如您所说,问题出在 SSL 证书验证期间。我重写了这个验证以始终返回 true,它的工作,我终于可以从 Stripe 获得一个令牌!我认为这是由于 Unity (.NET 2.0) 使用的旧版本的 .NET。但是这个解决方案并不是很优雅,所以我会试试这个证书包。谢谢!
  • 我尝试导入证书包,但没有解决问题...我保留了我的 ulgy 解决方案。

标签: c# stripe-payments restsharp


【解决方案1】:

正如我在 cmets 中所说,我在使用 .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 进行通信,所以我认为没关系! ;)

【讨论】:

  • 您可能想检查这是否符合 PCI 标准,我猜可能不符合。
猜你喜欢
  • 2023-04-08
  • 1970-01-01
  • 2022-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多