node.js
글쓴이: yjg99 / 작성시간: 월, 2010/12/27 - 5:26오후
#!/usr/bin/env node
var crypto= require('crypto')
var http = require("http");
var sys = require('sys');
var querystring = require("querystring");
var url = "/account/notifications.xml";
var message = "AJAXIAN.KR Status Message";
var messageDescription = "Status report from AJAXIAN.KR activities";
var messageTitle = "제목";
var params = {
"user_credentials": "AppNotifications에 등록된 자신의 등록키",
"notification[message]": message,
"notification[long_message]": messageDescription,
"notification[title]": messageTitle,
"notification[long_message_preview]": "메세지 미리보기",
"notification[message_level]": "0",
"notification[silent]": "0",
"notification[action_loc_key]": "Open",
"notification[run_command]": "http://ajaxian.kr",
"notification[sound]": "5.caf"
};
params = querystring.stringify( params );
var headers = {
"User-Agent": "NodeJs HTTP Client",
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": params.length,
"Accept": "text/plain",
"Host": "127.0.0.1"
};
var creds = crypto.createCredentials({ });인증서가 없을 경우, 빈 Object를 인자로 줍니다.
var httpClient = http.createClient(443, "www.appnotifications.com", true, creds);
var request = httpClient.request("POST", url, headers );//POST의 경우 request BODY에 써야합니다
request.write( params );
httpClient.addListener("secure", function () {
var verified = httpClient.verifyPeer();
if(!verified) this.end();
});
var result= "";
request.addListener("response", function (response) {
response.addListener("data", function (chunk) {
result+= chunk
});
response.addListener("end", function () {
sys.puts(result)
});
});
request.end();
//---------------------------
//process.stdout
//peer a message //Close the connection //송신
net = require("net");
s.net.createServer();
net.on('connection',function(c){
c.end('hello');
});
s.listen(8000)
//수신
var stst =require('fa').stat;
stat('/etc/passwd/', function(err, s){
if(err) throw err;
console.log('modified : %s',s.mtime);
});
//http Server streaming requests hung while waiting for other things
var http =require('http');
var server =http.createServer(function(req,res){
res.writeHead(200,('content-type':'text/plain'});
res.write( "hello \r\n");
setTimeout(function(0{
res.end('world \r\n');
},2000);
})'
server.lieten(8000);
</script>Forums:


댓글 달기