跳到主要内容
CNode
查看回复

回复 (20)

request

request

@vincentLiuxiang 谢谢

@44886 谢谢

undefined

B
blackmatch#159 年前

request没用过,之前写爬虫用superagent,不知道能不能满足你的需求。。。

L
libook#129 年前

有一个库叫做request,自己搜,看文档。

V
vincentLiuxiang#119 年前

这个看node文档就能搞定啊。。。 贴一段用http原生模块写的,不喜欢promise的化,把promise扔掉好了

var http = require('http');
var Promise = require("bluebird");

module.exports = function(options, body) {
  return new Promise(function(resolve, reject) {
  	var httpBody = options.body || body;
    var req = http.request(options, (res) => {
      var chunks = [];
      res.on('data', (chunk) => {
        chunks.push(chunk);
      });
      res.on('end', () => {
        resolve({
          statusCode: res.statusCode,
          headers: res.headers,
          body: Buffer.concat(chunks)
        });
      })
    });

    if (httpBody) {
      req.write(httpBody);
    }
    req.end();

    req.on('error', (e) => {
      reject(e);
    })

    if (options.timeout) {
      req.setTimeout(options.timeout, () => {
        req.abort();
      })
    }
  })
}
J
jeeinn#109 年前

superagent

M
magicdawn#89 年前

request-promise 设代理方便

S
stonephp#710 年前

axios 用了就知道了

4
44886#610 年前

相比request 我更喜欢 superagent

D
DevinXian#510 年前

request http(s) request-promise urllib

N
nnliang#410 年前
const rp = require('request-promise')
const options = {
	url, headers,......
}
rp.post(options).then(t => {
	......
})
K
kiinlam#310 年前

var http = require('http'); http.request(opt, function () {});

Z
zhaixg#210 年前

request的基本功能就能实现

A
ajaxQWER#110 年前

request

参与回复

登录后即可参与回复。登录