Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created March 10, 2010 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isaacs/328466 to your computer and use it in GitHub Desktop.
Save isaacs/328466 to your computer and use it in GitHub Desktop.
var client = http.createClient(u.port || (u.protocol === "https:" ? 443 : 80), u.hostname);
client.request("PUT", u.pathname, headers);
client.write(what, "utf8");
client.addListener("response", function (response) {
if (response.statusCode !== 200) return cb(new Error(
"Status code " + response.statusCode + " from PUT "+where));
var data = "";
response
.setBodyEncoding("utf8")
.addListener("data", function (chunk) { data += chunk })
.addListener("end", function () {
try {
data = JSON.parse(data);
} catch (ex) {
return cb(ex);
}
if (data.error) return cb(new Error(data.error));
cb(null, data);
});
});
client.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment