美文网首页
网络资源请求工具

网络资源请求工具

作者: 段煜华 | 来源:发表于2020-11-18 14:26 被阅读0次

request

截至2020年2月11日,请求完全被弃用。预计不会出现新的变化。事实上,已经有一段时间没有飞机着陆了。
https://github.com/request/request#readme

const request = require('request');
request('http://www.google.com', function (error, response, body) {
  console.error('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.
});

superagent

小型渐进客户端HTTP请求库,和Node.js模块具有相同的API,支持许多高级HTTP客户端特性
https://github.com/visionmedia/superagent

const superagent = require('superagent');

// callback
superagent
  .post('/api/pet')
  .send({ name: 'Manny', species: 'cat' }) // sends a JSON post body
  .set('X-API-Key', 'foobar')
  .set('accept', 'json')
  .end((err, res) => {
    // Calling the end function will send the request
  });

// promise with then/catch
superagent.post('/api/pet').then(console.log).catch(console.error);

// promise with async/await
(async () => {
  try {
    const res = await superagent.post('/api/pet');
    console.log(res);
  } catch (err) {
    console.error(err);
  }
})();

cheerio

为服务器特别定制的,快速、灵活、实施的jQuery核心实现.
https://github.com/cheeriojs/cheerio/wiki/Chinese-README

const cheerio = require('cheerio');
const $ = cheerio.load('<h2 class="title">Hello world</h2>');

$('h2.title').text('Hello there!');
$('h2').addClass('welcome');

$.html();
//=> <html><head></head><body><h2 class="title welcome">Hello there!</h2></body></html>

puppeteer

以 Chromium 为基础开发的 Node 端无头浏览器
https://github.com/puppeteer/puppeteer

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
})();

whistle

https://github.com/avwo/whistle
基于 Node 实现的跨平台抓包调试代理工具,有以下基本功能:

查看 HTTP、HTTPS、HTTP2、WebSocket、TCP 请求响应数据
修改 HTTP、HTTPS、HTTP2、WebSocket、TCP 请求响应数据
修改请求 url、方法、头部、内容等
修改响应状态码、头部、内容,并支持本地替换等
修改 WebSocket 和 TCP 收发的帧数据
设置 hosts(支持 IPv6)、http-proxy、https-proxy、socks
作为HTTP代理或反向代理
集成常用的 web 调试工具,如 weinre 和 log 等
支持用 Node 编写插件扩展

相关文章

  • 网络资源请求工具

    request 截至2020年2月11日,请求完全被弃用。预计不会出现新的变化。事实上,已经有一段时间没有飞机着陆...

  • NSURLConnection请求网络资源

    在做关于请求网络资源的时候,犯了两次一下错误,为了以后不在犯相同的错误决定百度一下,作为自己的学习笔记。 当现实错...

  • iOS 网络篇请求方法(GET & POST)

    1.网络知识 URL:是网络资源的唯一标识 HTTP请求包含三部分:请求行、请求头、请求体 HTTP服务器与应用服...

  • 网络资源加载方式(一)

    URLLoading System( 网络资源加载) Foundation框架中提供了资源网络请求部分的基本组件,...

  • Flutter获取图片大小(网络图片和本地图片)

    可以获取图片的大小 使用 本地资源使用: 网络资源使用: AsperctRaioImage工具类

  • restful 理解。

    restful是用来描述网络资源,使用GET,POST,PUT,DELETE请求来区分对资源的不同操作。 但是很多...

  • iOS开发 - Swift实现清除缓存功能

    前言: 开发移动应用时,请求网络资源是再常见不过的功能。如果每次都去请求,不但浪费时间,用户体验也会变差,所以移动...

  • Swift_清理缓存功能

    前言 开发移动应用时,请求网络资源是再常见不过的功能。如果每次都去请求,不但浪费时间,用户体验也会变差,所以移动应...

  • React Native 上手 - 7.网络

    上一篇:React Native 上手 - 6.ListView 大部分 App 都离不开网络资源请求。React...

  • 一文读懂什么是浏览器缓存

    一、什么是浏览器缓存? 为了节约网络资源的加速浏览,浏览器在用户磁盘上对最近请求过的文档进行存储,当访问者再次请求...

网友评论

      本文标题:网络资源请求工具

      本文链接:https://www.haomeiwen.com/subject/qufciktx.html