Created
August 25, 2010 16:52
-
-
Save KOBA789/549844 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 spawn = require("child_process").spawn; | |
exports.cURL = function (url, method) { | |
this.url = url; | |
this.method = method; | |
this.query = new Object(); | |
this.param = new Array(); | |
this.access = function (callback) { | |
var parameter = new Array(); | |
var queryString = new String(); | |
if (this.method == "POST") { | |
for (var key in this.query) { | |
parameter.push("-d", key + "=" + this.query[key]); | |
} | |
} else { | |
for (var key in this.query) { | |
queryString += "&" + key + "=" + this.query[key]; | |
} | |
if (queryString) { | |
queryString = "?" + queryString.substring(1); | |
} | |
} | |
parameter.push(this.url + queryString); | |
var curl = spawn("curl", parameter); | |
var stdout = new String(), | |
stderr = new String(); | |
curl.stdout.on("data", function (data) { | |
stdout += data; | |
}); | |
curl.stderr.on("data", function (data) { | |
stderr += data; | |
}); | |
curl.on("exit", function (status) { | |
callback(stdout, stderr, status); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment