2009-06-04 10:49:01 +02:00
|
|
|
var c = new node.http.Client(8000, "127.0.0.1");
|
2009-05-19 13:12:46 +02:00
|
|
|
|
2009-06-04 12:36:08 +02:00
|
|
|
c.onError = function () {
|
|
|
|
puts("http client connection error.");
|
|
|
|
};
|
|
|
|
|
2009-05-19 22:32:41 +02:00
|
|
|
var req = c.get("/bytes/123", [["Accept", "*/*"]]);
|
2009-05-19 13:12:46 +02:00
|
|
|
req.finish(function (res) {
|
2009-06-04 10:49:01 +02:00
|
|
|
puts("response 1: " + res.statusCode.toString());
|
2009-05-19 13:12:46 +02:00
|
|
|
|
|
|
|
res.onBody = function (chunk) {
|
2009-05-19 22:32:41 +02:00
|
|
|
chunk = chunk.encodeUtf8();
|
|
|
|
puts("response 1 body <" + JSON.stringify(chunk) + ">");
|
2009-05-19 13:12:46 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
res.onBodyComplete = function () {
|
2009-05-19 20:24:37 +02:00
|
|
|
puts("response 1 complete!");
|
2009-05-19 13:12:46 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
});
|
2009-05-19 20:24:37 +02:00
|
|
|
|
2009-05-19 22:32:41 +02:00
|
|
|
setTimeout(function () {
|
2009-06-04 15:41:40 +02:00
|
|
|
var req2 = c.get("/something/else");
|
|
|
|
//node.debug("start req2");
|
2009-05-19 22:32:41 +02:00
|
|
|
req2.finish(function (res) {
|
2009-06-04 10:49:01 +02:00
|
|
|
puts("response 2: " + res.statusCode.toString());
|
2009-05-19 20:24:37 +02:00
|
|
|
|
2009-05-19 22:32:41 +02: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);
|
2009-05-19 20:24:37 +02:00
|
|
|
|