java - 如何在 Node js/Java 中捕获网络调用?

标签 java node.js http httprequest firebug

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

我可以从代码中请求 URL,但我正在寻找方法来捕获正在进行的网络调用,获取网络调用中传递的请求参数

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

enter image description here

问题更新:在 Java 中是否可行?

最佳答案

如果您使用的是 request模块连同 request-debug模块:

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 } }

关于java - 如何在 Node js/Java 中捕获网络调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33296550/

相关文章:

java - 如何将java列表传递给coldfusion cfselect?

Node.js - NPM 包版本控制

javascript - 尽管调用文件相同,但为什么会出现连接错误?

angularjs - 在 AngularJS 中渲染远程 PNG 图像

c - c中的基本http代理,问题

java - 简单的java,字符串长度

java - 如何在RecyclerView Item中的populateViewHolder中设置addSnapshotListener和remove?

java - 无法通过 Phantom 连接到 Cassandra (NoHostAvailableException)

javascript - node.js 从 url 下载图像

java - Play Framework/Java : A good way to send x-www-form-urlencoded data back