无法在Charles [mac]中看到来自/到我的NodeJS应用程序的http流量

时间:2016-01-20 18:46:24

标签: macos charles-proxy

我正在运行Charles来检查节点js客户端和我的机器(Mac)上本地运行的服务之间的HTTP流量。我可以访问该服务,但在Charles中看不到任何痕迹。我尝试用我的机器的IP名称替换localhost,但仍然没有跟踪。如果我在Chrome中输入服务网址,我会看到跟踪。任何人都知道如何解决这个问题?

这是我的nodejs代码:

var thrift = require('thrift'); // I use Apache Thrift
var myService = require('./gen-nodejs/MyService'); // this is code generated by thrift compiler
var transport = thrift.TBufferedTransport();
var protocol = thrift.TBinaryProtocol();
var connection = thrift.createHttpConnection("localhost", 5331, {
  transport : transport,
  protocol : protocol,
  path: '/myhandler',
});

connection.on('error', function(err) {
    console.log(err);
});

// Create a client with the connection
var client = thrift.createHttpClient(myService, connection);
console.log('calling getTotalJobCount...');

client.getTotalJobCount(function(count)
{
    console.log('total job count = ' + count);
});

和我的代理设置: enter image description here

1 个答案:

答案 0 :(得分:0)

this链接的帮助下解决了这个问题。 Charles拦截穿过系统代理的流量,该代理在我的mac上为127.0.0.1:8888。这是正确的代码:

// give path to the proxy in argument to createHttpConnection
var connection = thrift.createHttpConnection('127.0.0.1', 8888, {
  transport : transport,
  protocol : protocol,
  path: 'http://localhost:5331/myhandler', // give the actual URL you want to connect to here
});

此外,需要使用thrift.TBufferedTransport代替thrift.TBufferedTransport()thrift.TBinaryProtocol代替thrift.TBinaryProtocol()