如何读取节点中发出的简单http请求的响应
how to read response of simple http request made in node
我正在使用节点中的 request
模块发出 http 请求。如何读取该请求的响应内容,以便我可以根据响应做出编程决策?
gulp.task("run-server-tests", function(){
var responseJson = request("http://myurl/run-server-tests")
plugins.util.log(responseJson); // not sure how to get at the response json
});
请求允许您使用回调函数,参见more detail
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Show the HTML for the Google homepage.
}
})
我正在使用节点中的 request
模块发出 http 请求。如何读取该请求的响应内容,以便我可以根据响应做出编程决策?
gulp.task("run-server-tests", function(){
var responseJson = request("http://myurl/run-server-tests")
plugins.util.log(responseJson); // not sure how to get at the response json
});
请求允许您使用回调函数,参见more detail
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Show the HTML for the Google homepage.
}
})