最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何与爱可信NPM包权威性

IT培训 admin 5浏览 0评论

如何与爱可信NPM包权威性

在过去,我用一些PHP代码查询这样的API

$str = file_get_contents('https://bla:[email protected]/rest/api/content/2950446?expand=body.storage');
$jsonObj = json_decode($str, true);

现在,我想用JS节点构建Alexa的技巧

我测试了这个

var session_url = '';


const fetchQuotes = async () => {
    try {
        const { data } = await axios.post(session_url, {}, {
            auth: {
                username: 'bla',
                password: 'bla'
            }});
        return data;
    } catch (error) {
        console.error('cannot fetch quotes', error);
    }
};

从我的理解,这也应该这样做。是这样吗?调用该网址,但我得到一个auth错误......

回答如下:

你把你的dataoptions领域,当你调用axios.post。你的数据需要axios.post的第二个参数不是第三位。

在做axios.post(url, {}, { somethingHere }data等于{}(空对象)。你应该这样做,而不是axios.post(url, { somethingHere }, { config }config部分是可选的。

Correct argument order

const fetchQuotes = async () => {
    try {
        const { data } = await axios.post(session_url, {
            auth: {
                username: 'bla',
                password: 'bla'
            }});
        return data;
    } catch (error) {
        console.error('cannot fetch quotes', error);
    }
};

如何与爱可信NPM包权威性

在过去,我用一些PHP代码查询这样的API

$str = file_get_contents('https://bla:[email protected]/rest/api/content/2950446?expand=body.storage');
$jsonObj = json_decode($str, true);

现在,我想用JS节点构建Alexa的技巧

我测试了这个

var session_url = '';


const fetchQuotes = async () => {
    try {
        const { data } = await axios.post(session_url, {}, {
            auth: {
                username: 'bla',
                password: 'bla'
            }});
        return data;
    } catch (error) {
        console.error('cannot fetch quotes', error);
    }
};

从我的理解,这也应该这样做。是这样吗?调用该网址,但我得到一个auth错误......

回答如下:

你把你的dataoptions领域,当你调用axios.post。你的数据需要axios.post的第二个参数不是第三位。

在做axios.post(url, {}, { somethingHere }data等于{}(空对象)。你应该这样做,而不是axios.post(url, { somethingHere }, { config }config部分是可选的。

Correct argument order

const fetchQuotes = async () => {
    try {
        const { data } = await axios.post(session_url, {
            auth: {
                username: 'bla',
                password: 'bla'
            }});
        return data;
    } catch (error) {
        console.error('cannot fetch quotes', error);
    }
};

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论