node http.request请求
var http = require('http'); var querystring = require('querystring'); var path = '/cricket/getRecordByOrderCode'; 地址 var postData = " "; var options = { hostname: 'xxx.xxx.com', //ip或地址 port: 80, //端口 一般是8080 path: path, method: 'GET', //POST 或 GET headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Content-Length': postData.length } }; var req = http.request(options, function(res) { console.log(req); console.log('STATUS: ' + res.statusCode); //状态码 console.log('HEADERS: ' + JSON.stringify(res.headers)); //响应头 res.setEncoding('utf8'); res.on('data', function(chunk) { console.log(chunk); }); }); req.on('error', function(e) { console.log('problem with request: ' + e.message); }); // write data to request body req.write(postData); req.end();