-
-
Save mikeal/328472 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var client = http.createClient(u.port || (u.protocol === "https:" ? 443 : 80), u.hostname); | |
var request = client.request("PUT", u.pathname, headers); | |
request.write(what, "utf8"); | |
request.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); | |
}); | |
}); | |
request.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment