Axios无法访问getpocket API

时间:2018-09-16 18:08:30

标签: javascript api axios pocket

我可以使用curl发出oauth请求,但是使用axios时,我会收到有关缺少使用者密钥的错误

X错误 缺少用户密钥。

这发生在发出请求的“选择”阶段。

 axios({
  method: 'post',
  url: 'https://getpocket.com/v3/oauth/request',
  data: {
    'consumer_key': 'xxxx-xxxxxxxxxxxxxxx',
    'redirect_uri': 'http://localhost:8080/'
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>

这是卷曲请求

curl https://getpocket.com/v3/oauth/request --insecure -X POST -H "Content-Type: application/json" -H "X-Accept: application/json" -d "{\"consumer_key\":\"xxxx-xxxxxx\",\"redirect_uri\":\"http://localhost:8080/\"}"

1 个答案:

答案 0 :(得分:0)

尝试将标头添加到您的请求中以接受json:

axios({
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json;charset=UTF-8'
    },
    url: 'https://getpocket.com/v3/oauth/request',
    data: {
        'consumer_key': 'xxxx-xxxxxxxxxxxxxxx',
        'redirect_uri': 'http://localhost:8080/'
    }
});