/****代码部分****/
var http = require('http');
var querystring = require('querystring');
var postData = querystring.stringify({
'content': '再接再厉,更加努力的好好学习天天向上',
'cid': 709
})
var options = {
hostname: 'www.tianmg.com',
port: 80,
path: '/course/docoment',
method: 'POST',
headers: {
'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-CN,zh;q=0.8',
'Connection':'keep-alive',
'Content-Length':postData.length,
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie':'tianmg_uuid=70242a20-5712-451c-ac97-ebdf6f371be8; tianmg_isnew_ct=1451440514; loginstate=1; apsid=ZkZDk1OTMxOGUxNTBkNWRhYzczY2ZhNGJiY2ZhZjcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMTAxMDM4MQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5NTczMTQ3MjRAcXEuY29tAAAAAAAAAAAAAAAAAAAAADcxZDJhMDc3ZTU2YWFlZDM0MmE5Y2JhYjFmMDQ1ZGYyGY%2FGVxmPxlc%3DN2; last_login_username=957314724%40qq.com; PHPSESSID=hul9p17hrro2erllb8c43e1j45; tianmg_isnew=2; cvde=57c8d5ee44321-4; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1472630492,1472779758; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1472779779',
'Host':'www.tianmg.com',
'Origin':'http://www.tianmg.com',
'Referer':'http://www.tianmg.com/comment/709',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36',
'X-Requested-With':'XMLHttpRequest'
}
}
var req = http.request(options, function(res) {
console.log('Status:' + res.statusCode);
console.log('headers:' + JSON.stringify(res.headers));
res.on('data', function(chunk) {
console.log(Buffer.isBuffer(chunk));
console.log(typeof chunk);
});
res.on('end', function() {
console.log('评论完毕!');
})
})
req.on('error', function(e) {
console.log('Error:' + e.message);
})
req.write(postData);
req.end();
/****控制台部分****/
D:\nodejs\node-1\scott\tianmg\beginning>node comment.js
Status:302
headers:{"server":"nginx","date":"Fri, 02 Sep 2016 02:03:07 GMT","content-type":
"text/html","transfer-encoding":"chunked","connection":"keep-alive","expires":"T
hu, 19 Nov 1981 08:52:00 GMT","cache-control":"no-store, no-cache, must-revalida
te, post-check=0, pre-check=0","pragma":"no-cache","location":"/error/noexists"}
评论完毕!
求高手指导 |