gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:32:58 25 4
gpt4 key购买 nike

在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com