request 模拟post提交表单
node.js环境下,利用request 模拟post提交表单
需要 formstream 插件配合使用.
npm install request formstream
var request = require('request') , FormStream = require('formstream') var form = FormStream() .field('name', '一介布衣') .file('head_image', '100x100.png') var upload = request.post('http://yijiebuyi.com/page', { headers: form.headers() }, function (err, res, rtn) { //...返回状态处理 }) form.pipe(upload)
将form 表单信息转化成formstream 流,然后将此流 pipe 到 request 的post 流上.