如何捕获节点js / Java中的networking调用?

在Firefox的firebug插件中,有一个名为“Net”的选项卡,它捕获当我们从浏览器点击URL时所做的所有networking调用

我可以从代码中请求URL,但我正在设法捕获正在进行的networking调用,获取在networking调用中传递的请求参数

这可以使用NodeJS / Java来完成吗?

在这里输入图像说明

问题更新:是否可以在Java中使用?

如果使用请求模块和请求debugging模块:

var request = require('request') var debug = require('request-debug') debug(request) request('http://google.com') 

这是执行上面的代码后,我在控制台中看到的:

 { request: { debugId: 1, uri: 'http://google.com/', method: 'GET', headers: { host: 'google.com' } } } { redirect: { debugId: 1, statusCode: 302, headers: { 'cache-control': 'private', 'content-type': 'text/html; charset=UTF-8', location: 'http://www.google.bg/?gfe_rd=cr&ei=AgEqVt-BLqOz8we1v5P4Cw', 'content-length': '258', date: 'Fri, 23 Oct 2015 09:42:26 GMT', server: 'GFE/2.0', connection: 'close' }, uri: 'http://www.google.bg/?gfe_rd=cr&ei=AgEqVt-BLqOz8we1v5P4Cw' } } { request: { debugId: 1, uri: 'http://www.google.bg/?gfe_rd=cr&ei=AgEqVt-BLqOz8we1v5P4Cw', method: 'GET', headers: { referer: 'http://google.com/', host: 'www.google.bg' } } } { response: { debugId: 1, headers: { date: 'Fri, 23 Oct 2015 09:42:26 GMT', expires: '-1', 'cache-control': 'private, max-age=0', 'content-type': 'text/html; charset=windows-1251', p3p: 'CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."', server: 'gws', 'x-xss-protection': '1; mode=block', 'x-frame-options': 'SAMEORIGIN', 'set-cookie': [Object], 'accept-ranges': 'none', vary: 'Accept-Encoding', connection: 'close' }, statusCode: 200 } } 

我创build了这个使用http.IncomingMessage对象读取三个有趣的属性(request.method,request.url和request.headers)

  //Lets require/import the HTTP module var http = require('http'); //Lets define a port we want to listen to const PORT=8080; //We need a function which handles requests and console request info function handleRequest(request, response){ console.log("==================="); console.log("request.url : "+request.url); console.log("==================="); console.log("request.method : "+request.method); console.log("==================="); console.log("request.headers : "+JSON.stringify(request.headers)); console.log("==================="); console.log("request.httpVersion : "+request.httpVersion); console.log("==================="); response.end(); } //Create a server var server = http.createServer(handleRequest); //Lets start our server server.listen(PORT, function(){ //Callback triggered when server is successfully listening. Hurray! console.log("Server listening on: http://localhost:%s", PORT); }); 

在节点中,我们有morgan来查看日志。 虽然它可能不完全服务于你所要求的。 但它用于查看所有通过节点进行的调用。