node/test_client.js

37 lines
864 B
JavaScript
Raw Normal View History

2009-05-19 19:12:46 +08:00
var c = new node.http.Client(8000, "localhost")
2009-05-20 04:32:41 +08:00
var req = c.get("/bytes/123", [["Accept", "*/*"]]);
2009-05-19 19:12:46 +08:00
req.finish(function (res) {
puts("response 1: " + res.status_code.toString());
2009-05-19 19:12:46 +08:00
res.onBody = function (chunk) {
2009-05-20 04:32:41 +08:00
chunk = chunk.encodeUtf8();
puts("response 1 body <" + JSON.stringify(chunk) + ">");
2009-05-19 19:12:46 +08:00
return true;
};
res.onBodyComplete = function () {
puts("response 1 complete!");
2009-05-19 19:12:46 +08:00
return true;
};
});
2009-05-20 04:32:41 +08:00
setTimeout(function () {
var req2 = c.get("/something/else", []);
req2.finish(function (res) {
puts("response 2: " + res.status_code.toString());
2009-05-20 04:32:41 +08:00
res.onBody = function (chunk) {
chunk = chunk.encodeUtf8();
puts("response 2 body <" + JSON.stringify(chunk) + ">");
return true;
};
res.onBodyComplete = function () {
puts("response 2 complete!");
return true;
};
});
}, 2000);