gpt4 book ai didi

node.js - NODEJS - AXIOS : Error : The "url" argument must be of type string. 在 Url.parse 接收到类型对象

转载 作者:搜寻专家 更新时间:2023-10-31 22:58:49 24 4
gpt4 key购买 nike

我正在尝试使用 AXIOS 从 rest API 获取数据,如下所示:

require('dotenv').config();
const axios = require('axios');

var url = 'https://931eb067-05c0-492a-8129-48ebfc27d426-bluemix.cloudant.com/dummy/_design/NEW_VIEW_DESIGN/_view/new-view?include_docs=true';
axios.get({url,auth: {
username: process.env.account,
password: process.env.password
}}).then((res)=>{console.log(res.data);})
.catch((e)=>{console.log(e)});

我可以通过提供凭据单独访问提到的 URL,但在使用 AXIOS 时出现以下错误

The "url" argument must be of type string. Received type object at Url.parse

出了什么问题?

最佳答案

axios.get({url,auth: {
username: process.env.account,
password: process.env.password
}}).then((res)=>{console.log(res.data);})

应该是

axios.get(url, { auth: {
username: process.env.account,
password: process.env.password
}}).then((res)=>{console.log(res.data);})

关于node.js - NODEJS - AXIOS : Error : The "url" argument must be of type string. 在 Url.parse 接收到类型对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52017939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com