简体   繁体   English

Axios条纹问题。 “ invalid_request_error”

[英]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.

相关问题 Stripe invalid_request_error:令牌不能作为 Source 传入 - Stripe invalid_request_error: A token may not be passed in as a Source loadStripe 一直给我 {type: "invalid_request_error", message: "Invalid API Key provided: undefined"} 错误 - loadStripe keeps giving me {type: "invalid_request_error", message: "Invalid API Key provided: undefined"} error INVALID_REQUEST_ERROR - VERSION_MISMATCH - 对象版本与最新的数据库版本不匹配 - INVALID_REQUEST_ERROR - VERSION_MISMATCH - Object version does not match latest database version 在 Stripe 中创建客户时出现无效请求错误 - Invalid request error while creating customer in Stripe 将条带 Curl 请求翻译成 Axios - Translate stripe Curl request to Axios elFinder问题。 尝试复制文件时,未定义不是函数错误 - elFinder issues. Undefined is not a function error when trying to copy file 使用axios的发布请求失败,并显示“对预检的响应无效”错误 - Post request using axios fails with “Response for preflight is invalid” error 将javascript POST请求转换为Axios(使用Stripe) - Translate javascript POST request into Axios (using Stripe) .append问题。 限制.append - .append issues. Limit .append axios 的问题(“随机”网络错误) - Issues with axios (“random” network error)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM