首页 > 解决方案 > 400 Bad Request 使用 Axios 获取请求

问题描述

我正在阅读请求方法别名

axios.get(url[, config])

我试着做方法

const axios = require('axios')
let data = new Date()
let timer = date.getTime()
const config = {
  'kc-api-key': 'xxxxxxxxxxxx', // primary key
  'kc-api-sign': 'xxxxxxxxxxx', // screat key
  'kc-api-timestamp' : timer,      // timestamp
  'kc-api-passpharase : 'xxxxxxx ' // passpharase

axios.get('https://api.kucoin.com/api/v1/accounts/',config)
  .then(r => {
    console.log('Ok')
  })
  .catch(e => {
    console.log('Error')
  })

return 400 Bad Request -- 无效的请求格式现在我不知道如何解决它。

消息:“请求失败,状态码 400”

标签: javascriptnode.jshttpgetaxios

解决方案


我很确定这是定义标题的方法:

const config = {
    headers: {
        'kc-api-key': 'xxxxxxxxxxxx', // primary key
        'kc-api-sign': 'xxxxxxxxxxx', // screat key
        'kc-api-timestamp' : timer,      // timestamp
        'kc-api-passpharase : 'xxxxxxx ' // passpharase
    }
}

axios.get('https://api.kucoin.com/api/v1/accounts', config)

推荐阅读