如何记录来自Webstorm内节点的出局https请求 [英] how to log OUTGOING https requests from node within webstorm

查看:217
本文介绍了如何记录来自Webstorm内节点的出局https请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一起整理一些调用外部Web服务的node.js代码,但结果却很糟糕.我想记录原始请求和响应,以便我可以检查它.

I'm hacking together some node.js code that calls an external webservice and I'm getting bad results. I'd like to log the raw request and response so that I can inspect it.

事情是这样:我不是直接使用http库,而是通过OAuth库使用它.

Here's the thing: I'm not consuming the http library directly, I'm consuming it through an OAuth library.

我已经在oauth库代码中添加了调试语句,但我不喜欢它.现在看来,我将不得不进入http库并开始弄乱它?这是不正确的.

I'm already adding debug statements in the oauth library code and I don't like it. Now it looks like I'm going to have to go into http library and start messing with that? This can't be correct.

如果我在窗户上,我会开小提琴手.一位朋友提到Wireshark,但Wireshark告诉我我必须安装X11.真的吗?我不会掉进那个兔子洞里.

If I was on windows, I'd fire up fiddler. A friend mentioned wireshark but wireshark tells me I have to install X11. Really? I'm not going down that rabbit hole.

然后我尝试了节点检查器,但是我认为这是针对服务器代码而不是客户端代码的.它说您想在附加之前启动节点进程.好吧,我的节点流程是一个测试用例(誓言),该用例在启动后不久就结束了……所以那里没有运气.

Then I tried node-inspector, but I think that is for server code not client code. It says your suppose to start your node process before attaching. Well my node process is a test case (vows) that ends shortly after is starts... so no luck there.

我想,除了jeez,任何堆栈都很难做到这一点,这让我很想念.net!

I guess this would difficult with any stack but jeez, it makes me miss .net!

那么,当使用node.js作为客户端到山狮上的外部Web服务的客户端时,我该如何检查整个线路呢?

So, how can I inspect what's going over the wire when using node.js as client to external webservice on mountain lion?

谢谢! 丹

推荐答案

出于相同的原因,已设法在http/https请求上安装钩子.

Managed to install a hook on http/https request for the same reason.

function requestLogger(httpModule){
    var original = httpModule.request
    httpModule.request = function(options, callback){
      console.log(options.href||options.proto+"://"+options.host+options.path, options.method)
      return original(options, callback)
    }
}

requestLogger(require('http'))
requestLogger(require('https'))

这篇关于如何记录来自Webstorm内节点的出局https请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆