首页 > Web开发 > 详细

node.js http.get 和http.post 数据

时间:2014-11-01 00:52:55      阅读:374      评论:0      收藏:0      [点我收藏+]
http.get(‘http://codestudy.sinaapp.com‘, function (response) {});

node.js http post 样例:
var reqData={ id:‘111‘ }; var post_options = { host: ‘127.0.0.1‘ port: ‘8888‘, path: ‘/api/list‘, method: ‘POST‘, headers: { ‘Content-Type‘: ‘application/x-www-form-urlencoded‘, ‘Content-Length‘: reqData.length } }; var post_req = http.request(post_options, function (response) { var responseText=[]; var size = 0; response.on(‘data‘, function (data) { responseText.push(data); size+=data.length; }); response.on(‘end‘, function () { // Buffer 是node.js 自带的库,直接使用 responseText = Buffer.concat(responseText,size); callback(responseText); }); }); // post the data post_req.write(reqData); post_req.end();

  

node.js http.get 和http.post 数据

原文:http://www.cnblogs.com/hubcarl/p/4066199.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!