node.js http.get 和http.post 數據


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();

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM