• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript needle.get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中needle.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: ResponsePipeline

function ResponsePipeline() {
    needle.get('http://stackoverflow.com/feeds', { compressed: true, headers: {
        Authorization: 'bearer 12dsfgsdgsgq'
    } }, function (err, resp) {
        console.log(resp.body); // this little guy won't be a Gzipped binary blob 
        // but a nice object containing all the latest entries
    });

    var options = {
        compressed: true,
        follow: 5,
        rejectUnauthorized: true
    };

    // in this case, we'll ask Needle to follow redirects (disabled by default), 
    // but also to verify their SSL certificates when connecting.
    var stream = needle.get('https://backend.server.com/everything.html', options);

    stream.on('readable', function () {
        var data: any;
        while (data = this.read()) {
            console.log(data.toString());
        }
    });
}
开发者ID:DavidKDeutsch,项目名称:DefinitelyTyped,代码行数:25,代码来源:needle-tests.ts


示例2: ResponsePipeline

function ResponsePipeline() {
    needle.get('http://stackoverflow.com/feeds', { compressed: true }, function (err, resp) {
        console.log(resp.body); // this little guy won't be a Gzipped binary blob
        // but a nice object containing all the latest entries
    });

    var options = {
        compressed: true,
        follow: 5,
        rejectUnauthorized: true
    };

    // in this case, we'll ask Needle to follow redirects (disabled by default),
    // but also to verify their SSL certificates when connecting.
    var stream = needle.get('https://backend.server.com/everything.html', options);

    stream.on('readable', function () {
        var data: any;
        while (data = stream.read()) {
            console.log(data.toString());
        }
    });

    stream.on('end', function(err: any) {
        // if our request had an error, our 'end' event will tell us.
        if (!err) console.log('Great success!');
    })
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:28,代码来源:needle-tests.ts


示例3: HttpGetWithBasicAuth

function HttpGetWithBasicAuth() {
    needle.get('https://api.server.com', { username: 'you', password: 'secret' }, function(err, resp) {
        // used HTTP auth
    });
    needle.get('https://username:[email protected]', function(err, resp) {
        // used HTTP auth from URL
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:8,代码来源:needle-tests.ts


示例4: Usage

function Usage() {
    // using callback
    needle.get('http://ifconfig.me/all.json', function (error, response) {
        if (!error)
            console.log(response.body.ip_addr); // JSON decoding magic. :)
    });

    // using streams
    var out: any; // = fs.createWriteStream('logo.png');
    needle.get('https://google.com/images/logo.png').pipe(out);
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:11,代码来源:needle-tests.ts


示例5: Usage

function Usage() {
    // using promises
    needle('get', 'http://ifconfig.me/all.json')
        .then((resp) => console.log(resp.body.ip_addr));

    // using callback
    needle.get('http://ifconfig.me/all.json', (error, response) => {
        if (!error)
            console.log(response.body.ip_addr); // JSON decoding magic. :)
    });

    // using streams
    const out = fs.createWriteStream('file.txt');
    needle.get('https://google.com/images/logo.png').pipe(out);
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:15,代码来源:needle-tests.ts


示例6: reject

    let promise = new Promise<SubscriptionAccount>((resolve, reject) => {
        needle.get(sogouSearchUrl, options, (error: any, httpResponse: any) => {
            if (error) {
                reject('Failed to retrieve content from the given url.');
                return;
            }

            if (httpResponse.statusCode === 200) {
                // Successfully retrieve the result.
                let responseHTML = cheerio.load(httpResponse.body);
                let subscriptionItem = responseHTML(AccountSelectors.BASE);
                while (subscriptionItem.length > 0) {
                    if (subscriptionItem.find(AccountSelectors.WECHAT_ID).length > 0) {
                        let resultWechatId = subscriptionItem.find(AccountSelectors.WECHAT_ID).text();
                        if (resultWechatId !== this.wechatId) {
                            subscriptionItem = subscriptionItem.next();
                            continue;
                        }

                        let name = subscriptionItem.find(AccountSelectors.NAME).text();
                        let resultUrl = subscriptionItem.attr('href');
                        let accountImage = subscriptionItem.find(AccountSelectors.IMG).attr('src');
                        let account = new SubscriptionAccount(name, resultUrl, accountImage);
                        resolve(account);
                        return;
                    }
                    subscriptionItem = subscriptionItem.next();
                }
            } 
            
            reject(httpResponse.body);
        });
    });
开发者ID:eastenluis,项目名称:wechat-subscription,代码行数:33,代码来源:wechat-subscription-account.ts


示例7: Various

function Various() {
    // using promises
    needle('get', 'https://news.ycombinator.com/rss')
        .then((resp) => {
            // if xml2js is installed, you'll get a nice object containing the nodes in the RSS
        });
    needle('get', 'http://upload.server.com/tux.png', { output: '/tmp/tux.png' })
        .then((resp) => {
            // you can dump any response to a file, not only binaries.
        });
    needle('get', 'http://search.npmjs.org', { proxy: 'http://localhost:1234' })
        .then((resp) => {
            // request passed through proxy
        });

    // using callback
    needle.get('https://news.ycombinator.com/rss', (err, resp, body) => {
        // if xml2js is installed, you'll get a nice object containing the nodes in the RSS
    });
    needle.get('http://upload.server.com/tux.png', { output: '/tmp/tux.png' }, (err, resp, body) => {
        // you can dump any response to a file, not only binaries.
    });
    needle.get('http://search.npmjs.org', { proxy: 'http://localhost:1234' }, (err, resp, body) => {
        // request passed through proxy
    });

    // using streams
    const stream1 = needle.get('http://www.as35662.net/100.log');
    stream1.on('readable', () => {
        let chunk: any;
        while (chunk = stream1.read()) {
            console.log('got data: ', chunk);
        }
    });
    const stream2 = needle.get('http://jsonplaceholder.typicode.com/db', { parse: true });
    stream2.on('readable', () => {
        let node: any;

        // our stream2 will only emit a single JSON root node.
        while (node = stream2.read()) {
            console.log('got data: ', node);
        }
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:44,代码来源:needle-tests.ts


示例8: HttpGetWithBasicAuth

function HttpGetWithBasicAuth() {
    // using promises
    needle('get', 'https://api.server.com', { username: 'you', password: 'secret' })
        .then((resp) => {
            // used HTTP auth
        });
    needle('get', 'https://username:[email protected]')
        .then((resp) => {
            // used HTTP auth from URL
        });

    // using callback
    needle.get('https://api.server.com', { username: 'you', password: 'secret' }, (err, resp) => {
        // used HTTP auth
    });
    needle.get('https://username:[email protected]', (err, resp) => {
        // used HTTP auth from URL
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:19,代码来源:needle-tests.ts


示例9: API_get

function API_get() {
    // using promises
    needle('get', 'google.com/search?q=syd+barrett')
        .then((resp) => {
            // if no http:// is found, Needle will automagically prepend it.
        });

    // using callback
    needle.get('google.com/search?q=syd+barrett', (err, resp) => {
        // if no http:// is found, Needle will automagically prepend it.
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:12,代码来源:needle-tests.ts



注:本文中的needle.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript needle.post函数代码示例发布时间:2022-05-25
下一篇:
TypeScript nedb.insert函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap