最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何与爱可信NPM包权威性

运维笔记admin18浏览0评论

如何与爱可信NPM包权威性

如何与爱可信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. 暂无评论