node.js以post请求方式发送http请求
varhttp=require('http');varquerystring=require('querystring');//请求参数varpostData=querystring.stringify({'name':"wangbin",'password':"123456",'serverId':2});varoptions={hostname:'192.168.1.135',port:3001,path:'/login',method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded','Content-Length':postData.length}};varreq=http.request(options,function(res){res.setEncoding('utf8');varresData=[];res.on('data',function(chunk){resData.push(chunk);});res.on('end',function(){vardata=resData.join("");console.log(data);})});req.on('error',function(e){console.log('problemwithrequest:'+e.message);});//发送请求req.write(postData);req.end();
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。