[英]Axios stripe issues. “invalid_request_error”
I am at my wits end! 我没办法! I am trying to create a customer via the stripe api. 我正在尝试通过Stripe API创建客户。 Using their example with curl i have no problems. 用他们的例子卷曲我没有问题。 Here is their example: 这是他们的例子:
curl https://api.stripe.com/v1/customers \\ -u sk_test_apikey: \\ -d description="Customer for zoey.brown@example.com" \\ -d source=tok_visa
It is when i try to do this with axios that i get an error "invalid_request_error" because it isn't properly parsing my data. 当我尝试使用axios执行此操作时,出现错误“ invalid_request_error”,因为它无法正确解析我的数据。 Here's what i've got: 这是我所拥有的:
export const registerNewUser = async (firstName, lastName, email, password) => {
let config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Bearer ${stripeTestApiKey}`
}
}
let data = {
email: `${email}`,
description: `Customer account for ${email}`
}
await axios.post(stripeCustomerUri, data, config)
.then(res => {
console.log("DEBUG-axios.post--res: ", res)
})
.catch(err => {
console.log(JSON.stringify(err, null, 2))
})
}
and in my console i see that stripe isn't receiving my data in the correct manner. 在我的控制台中,我看到条带没有以正确的方式接收我的数据。 Here's the (useful part of my) response json: 这是(我的有用部分)响应json:
"response": {
"data": {
"error": {
"type": "invalid_request_error",
"message": "Received unknown parameter: {\"email\":\"joe@blow.com\",\"description\":\"Customer account for joe@blow.com\"}", "param": "{\"email\":\"joe@blow.com\",\"description\":\"Customer account for joe@blow.com\"}" } },
Judging by all of my other attempts and this example error, I am not passing my data in the correct format... However, when i pass -d
to my curl command everything works as expected... If I send an empty string as data
it works as well... 从我的所有其他尝试和此示例错误判断,我没有以正确的格式传递数据...但是,当我将-d
传递给curl命令时,一切都按预期工作...如果我发送一个空字符串作为data
也很好...
does anyone have an idea why / how this is? 有谁知道为什么/这是怎么回事? How is the "data" object via curl differ from my javascript data object? 通过curl的“数据”对象与我的javascript数据对象有何不同?
问题是axios默认情况下使用application / json内容类型,并且条带化api需要以form-url编码...这需要在传递给条带化api之前使用诸如querystring之类的库来解析数据对象。有人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.