Javascript Axios条纹问题&引用;无效的“请求错误”;
我真是束手无策!我试图通过StripeAPI创建一个客户。使用他们的curl示例,我没有问题。 以下是他们的例子:Javascript Axios条纹问题&引用;无效的“请求错误”;,javascript,stripe-payments,axios,Javascript,Stripe Payments,Axios,我真是束手无策!我试图通过StripeAPI创建一个客户。使用他们的curl示例,我没有问题。 以下是他们的例子: curlhttps://api.stripe.com/v1/customers \ -密钥测试密钥:\ -d description=“zoey的客户。brown@example.com" \ -d source=tok_visa 当我尝试使用axios执行此操作时,会出现一个错误“invalid_request_error”,因为它没有正确解析我的数据。以下是我得到的: expo
curlhttps://api.stripe.com/v1/customers \
-密钥测试密钥:\
-d description=“zoey的客户。brown@example.com" \
-d source=tok_visa
当我尝试使用axios执行此操作时,会出现一个错误“invalid_request_error”,因为它没有正确解析我的数据。以下是我得到的:
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))
})
}
在我的控制台中,我看到stripe没有以正确的方式接收我的数据。以下是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\"}" } },
从我所有的其他尝试和这个示例错误判断,我没有以正确的格式传递数据。。。然而,当我将-d
传递给curl命令时,一切都按预期工作。。。如果我发送一个空字符串作为数据
它也可以工作
有人知道为什么会这样吗?通过curl的“数据”对象与我的javascript数据对象有何不同 问题在于axios默认使用application/json内容类型,stripe api需要表单url编码。。。这需要在传递到stripe api之前使用类似querystring的库解析数据对象。。。希望这对别人有帮助 问题在于axios默认使用application/json内容类型,stripe api需要表单url编码。。。这需要在传递到stripe api之前使用类似querystring的库解析数据对象。。。希望这对别人有帮助 谢谢你的解决方案。这个问题真的困扰着我。有关更多信息,请阅读('Using application/x-www-form-urlencoded format')部分。感谢您提供的解决方案。这个问题真的困扰着我。有关更多信息,请阅读(“使用应用程序/x-www-form-urlencoded format”)部分。