NODEJS - AXIOS : Error : The "url" argument must be of type string. Received type object at Url.parse
NODEJS - AXIOS : Error : The "url" argument must be of type string. Received type object at Url.parse
我正尝试使用 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);})
您已将 url
放入配置 confie 参数中,但它必须在配置之前。
axios.get(url, {auth: {
username: process.env.account,
password: process.env.password
}}).then((res)=>{console.log(res.data);})
.catch((e)=>{console.log(e)});
我正尝试使用 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);})
您已将 url
放入配置 confie 参数中,但它必须在配置之前。
axios.get(url, {auth: {
username: process.env.account,
password: process.env.password
}}).then((res)=>{console.log(res.data);})
.catch((e)=>{console.log(e)});