5 回复
var net = require(‘net’); var port = 12211; var host = 'openapi.exmail.qq.com’;
var client= new net.Socket(); client.setEncoding(‘binary’); var sendstr = 'ver=1385039902768&access_token=sdadas’; //连接到服务端 client.connect(port,host,function(){
console.log('here');
client.write("POST /openapi/listen HTTP/1.1\r\n"+
"Host: openapi.exmail.qq.com\r\n"+
"Connection: keep-alive\r\n"+
"Content-Length:"+ sendstr.length+"\r\n"+
"\r\n"+
sendstr
);
}); client.setKeepAlive(true);
client.on('timeout’, function(){
console.log('time out');
})
client.on('data’,function(data){ console.log('recv data:’+ data);
}); client.on('error’,function(error){
console.log('error:'+error);
client.destory();
}); client.on('close’,function(){
console.log('Connection closed');
});