【问题标题】:Axios get URL parameter string not acceptedaxios 获取 URL 参数字符串不被接受
【发布时间】:2018-10-11 09:50:54
【问题描述】:

为什么会报错:

““url”参数必须是字符串类型。接收到的类型未定义”

当我运行这段代码时:
附言我也试过用这个 URL 传入变量,但结果是一样的。

var axios = require('axios')();

module.exports = {
    async getJSONAsync(){


        let json = await axios.get('https://tutorialzine.com/misc/files/example.json');

        return json;
    }
};

注意:我在另一个带有 await 关键字的异步函数中使用了这个函数。 喜欢:

async begin() {

        try {
            let setup = new SetUp(this.bot);
            await testapi.getJSONAsync().then(function (json) {
                console.log(json)
            });
            let settings = await setup.prepareTest();
            let session = await settings.driver.getSession();
            logger.logDebug('Launching ' + this.test.name);

            return settings;
        }

        catch (e) {

            logger.logErr('Error when create settings for ' + this.test.name);
            throw e;

        }

    }

【问题讨论】:

    标签: javascript async-await axios ecmascript-2017


    【解决方案1】:
      require('axios')()
    

    这将导入 axios 并直接使用 no 参数调用它,因此它会抱怨它期望的 url 没有传递。也许只是不要在这里调用它?

    【讨论】:

    • 所以我应该像这样使用:var axios = require('axios'); var 应用程序 = axios;然后调用 app.get?
    • @littleJohnny jup.
    • 我是新来的,请问为什么要使用app变量?
    • @littleJohnny 你不必这样做。这完全取决于你。你也可以做require("axios").get("somurl") 或类似的事情。或const axios = require("axios"); axios.get("someurl") 或...
    • 我该如何解析我的回复?在哪个功能?像“开始”还是“Json”?
    猜你喜欢
    • 1970-01-01
    • 2017-08-11
    • 2021-06-29
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 2019-08-25
    • 1970-01-01
    相关资源
    最近更新 更多