var http = require("http");
http.getString("http://httpbin.org/get").then(function (r) {
// Argument (r) is string!
}).fail(function (e) {
// Argument (e) is Error!
console.log(e);
});
http.getJSON("http://httpbin.org/get").then(function (r) {
// Argument (r) is JSON!
}).fail(function (e) {
// Argument (e) is Error!
console.log(e);
});
http.getImage("http://www.google.com/images/errors/logo_sm_2.png").then(function (r) {
// Argument (r) is Image!
}).fail(function (e) {
// Argument (e) is Error!
console.log(e);
});
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
// Argument (response) is HttpResponse!
var statusCode = response.statusCode;
}).fail(function (e) {
// Argument (e) is Error!
console.log(e);
});
Get response headers
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
for (var header in response.headers) {
console.log(header + ":" + response.headers[header]);
}
}).fail(function (e) {
// Argument (e) is Error!
console.log(e);
});
http.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
// Argument (response) is HttpResponse!
// Content property of the response is HttpContent!
var str = response.content.toString();
var obj = response.content.toJSON();
var img = response.content.toImage();
}).fail(function (e) {
// Argument (e) is Error!
console.log(e);
});