[英]How to send Stripe's secret key when making a raw HTTP POST request to Stripe
Because the Stripe .NET nuget package / library is built on v1 of the Stripe API, and since then a few things have changed, I am making a raw HTTP request to a Stripe endpoint to add a new credit card to an existing customer's account. 因为Stripe .NET nuget包/库是在Stripe API的v1上构建的,从那时起一些事情发生了变化,我正在向Stripe端点发出原始HTTP请求,以向现有客户的帐户添加新的信用卡。
My question is: how do I send the Stripe secret key? 我的问题是:如何发送Stripe密钥? Looking at this CURL request , I assumed that it is sent as a basic authentication header. 看看这个CURL请求 ,我假设它是作为基本身份验证标头发送的。
So, here's what I did: 所以,这就是我做的:
var createCardUrl = string.Format(
"https://api.stripe.com/v1/customers/{0}/sources",
stripeCustomerId);
dynamic headers = new ExpandoObject();
headers.Authorization = string.Format("Basic {0}", Constants.StripeSecretKey);
dynamic body = new ExpandoObject();
body.source = stripeToken;
dynamic cardAdditionResult = Http.MakePostRequest(
createCardUrl,
headers,
body)
.ObjectFromJson();
Where my MakePostRequest
is as follows. 我的MakePostRequest
如下所示。
public static string MakePostRequest(string url,
IEnumerable<KeyValuePair<string, object>> headers = null,
string body = null)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
if (headers != null)
{
AddHeaders(request, headers);
}
if (!string.IsNullOrEmpty(body))
{
var data = Encoding.ASCII.GetBytes(body);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
return responseString;
}
I receive a 400 (Bad Request) from Stripe. 我从Stripe收到400(错误请求)。 Obviously, I am not sending the Stripe secret key the way I must. 显然,我不是按照必须的方式发送Stripe密钥。
如果你正在使用基本身份验证,Stripe secret api密钥应该是base 64编码,然后有一个:
之后(因为它会划分用户名和密码)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.