How to capture http messages from Request Node library with Fiddler

capture node js traffic
nodejs proxy request
nodejs request post
node request timeout
node request cookie
nodejs request json
request pipe nodejs
node-http-proxy

Regular client initiated requests to the node server are captured fine in Fiddler. However, requests sent from node to a web service are not captured. It did not help to pass in config for proxy (127.0.0.1:8888) to the request method. How can I route the request messages through Fiddler?

var http = require('http');
var request = require('request');

request.get(webserviceURL, { "auth" : {"user": "user", "pass" = "pass", sendImmediately: true },
"proxy" : { "host" : "127.0.0.1", "port" : 8888 }},
function (error, response) { console.log( "response received" );
});

Request repo: https://github.com/mikeal/request

I just tried to do this myself (using Fiddler and the request library from npm). Here's how I got it working:

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; // Ignore 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' authorization error

// Issue the request
request(
{
    method: "GET",
    uri: "https://secure.somewebsite.com/",
    proxy: "http://127.0.0.1:8888" // Note the fully-qualified path to Fiddler proxy. No "https" is required, even for https connections to outside.
},
function(err, response, body) {
    console.log("done");
});

This is with Fiddler2 using the default port and proxy options (and no proxy authentication).

It did not help to pass in config for proxy (127.0.0.1:8888) to the request method. How can I route the request messages through Fiddler? var http = require('http');  View HTTP Request in Fiddler. To inspect HTTP Web Request using Fiddler perform following steps. Click on the web request entry on left pane; Click on the Inspector Tab > Click Raw from top panel; View HTTP Response in Fiddler. To inspect HTTP Web Response using Fiddler perform following steps. Click on the web request entry on left pane

Fiddler works by setting your "Internet Options" (from start menu) "Connections" > "LAN Settings" > "Proxy Server" to its port, thus making all HTTP traffic (clients which obey this setting) go through it.

You should point your node.js client lib to use a proxy, the settings are written in that options dialog after you start Fiddler.

For a Node.js request, see, for instance: http://stackoverflow.com/questions HTTP libraries you're using to issue requests from the node script. For SSL however, this is not quite as simple – Fiddler can easily act as an HTTPS/SSL client to capture inbound requests from the server, but when it forwards the request to the client it has to also act as an SSL server and provide a certificate that the client trusts.

The proxy option should be a full url, like this:

proxy : "http://127.0.0.1:8888"

Regular client initiated requests to the node server are captured fine in Fiddler. However, requests sent from node to a web service are not  fiddler.proxyRequests(); // requests. fiddler.unproxyRequests(); HTTP/HTTPS module. If requests are sent with HTTP/HTTPS modules of Node.js, there is no global switch to turn on/off proxy settings for all requests. Some helper methods can be created to proxy an individual HTTP request to Fiddler. Below is the rest of the fiddler.js module:

At MyGet support, we sometimes have to capture HTTP(S) traffic in order to be able to diagnose the issue at hand. If this is the Setting up Fiddler for capturing requests. To capture Make sure to configure the npm proxy and use Fiddler: Regular client initiated requests to the node server are captured fine in Fiddler. However, requests sent from node to a web service are not captured. It did not help to pass in config for proxy (1 Stack Overflow. Products.

I've been wanting the same... an equivalent of the Network tab in chrome DevTools, only for Nodejs. Unfortunately, it doesn't appear as though one exists. I don't have Fiddler on macos, so this is how I went about stubbing the require('http') methods to log and pass though. Leaving this here in case I need it again or someone else finds it helpful. You can turn it on by attaching a debugger and require('filename')() the file containing this script.

module.exports = () => {
    const http = require('http');
    http._request = http.request;

    global.DO_LOG_AJAX = true;
    const log = str => {
        if (global.DO_LOG_AJAX) {
            console.debug(str);
        }
    };

    const flushLog = (requestLines, responseLines) => {
        if (global.DO_LOG_AJAX) {
            log([
                '----------------Begin Request-----------------------------------',
                ...requestLines,
                '----------------End Request / Begin Response--------------------',
                ...responseLines,
                '----------------End Reponse-------------------------------------',
            ].join('\n'));
        }
    };

    let write;
    let end;
    http.request = (...requestParams) => {
        const req = http._request(...requestParams);
        const { method, path, headers, host, port } = requestParams[0];
        const requestLogLines = [];
        requestLogLines.push(`${method} ${path}`);
        requestLogLines.push(`Host: ${host}:${port}`);
        for (const header of Object.keys(headers)) {
            requestLogLines.push(`${header}: ${headers[header]}`);
        }
        write = write || req.write;
        end = end || req.end;

        req.on('error', err => {
            log({ err });
        });

        req._write = write;
        req._end = end;
        const requestBody = [];
        req.write = (...writeParams) => {
            requestBody.push(writeParams[0].toString());
            return req._write(...writeParams);
        };
        req.end = (...endParams) => {
            if (endParams[0]) {
                requestBody.push(endParams[0].toString());
            }
            requestLogLines.push('');
            requestLogLines.push(requestBody.join(''));
            return req._end(...endParams);
        };

        const responseLogLines = [];
        req.once('response', response => {
            const responseBody = [];
            responseLogLines.push(`${response.statusCode} ${response.statusMessage}`);
            for (const header of Object.keys(response.headers)) {
                responseLogLines.push(`${header}: ${response.headers[header]}`);
            }
            const onData = chunk => {
                responseBody.push(chunk.toString());
            };
            const onClose = err => {
                responseLogLines.push('');
                responseLogLines.push(responseBody.join(''));
                responseLogLines.push('');
                responseLogLines.push(`--- ERROR --- ${err.toString()}`);
                flushLog(requestLogLines, responseLogLines);
                req.removeListener('data', onData);
            };
            const onEnd = () => {
                responseLogLines.push('');
                responseLogLines.push(responseBody.join(''));
                flushLog(requestLogLines, responseLogLines);
                req.removeListener('data', onData);
            };
            response.on('data', onData);
            response.once('close', onClose);
            response.once('end', onEnd);
        });

        return req;
    };
};

As they are written in NODE, I'm using the SOAP package from NPM to make requests to the EXCHANGE / Office 365 SOAP service. Unfortunately the Done! Your NODE http/https Traffic will now show up in Fiddler! image. In Fiddler2, go to the page Tools->Fiddler Options ->Connections, remove the trailing semicolon from the value in the "IE should bypass Fiddler for " field and restart Fiddler2. this solution solved my problem, hope can help someone if you are struggling with it.

Is there any configuration change I can make to monitor that outgoing /how-to-​capture-http-messages-from-request-node-library-with-fiddler  Half of goal is accomplished, since the source avobe can capture raw http requests excluding the first http request on a connection. This could be done by using event of socket in http.IncomingMessage.

Fiddler is a proxy which can capture both regular web traffic (HTTP) and In NodeJS, request is the most commonly used HTTP/REST library. Tutorial: Using Fiddler to Compose HTTP SOAP Requests to the AppFxWebService.asmx. This tutorial will guide you through the steps to create and execute an HTTP request with Fiddler. According to its website, Fiddler is a free web debugging proxy for any browser, system or platform.

I can capture http traffic using fiddler in a node.js script that uses the request library (i.e. npm install request) by adding these lines to the top of  Fiddler. Fiddler is a web debugging proxy tool that can capture HTTP(S) traffic. It can only run on Windows. To use: Download Fiddler. Open it. Clear your browser cache. Browse to your site. Visit the pages that are problematic and a contrasting non-problematic page if appropriate, for contrast.

Comments
  • Setting the proxy on the request object should be all you need to do, but I don't see a "proxy" property in the docs? nodejs.org/api/http.html#http_http_request_options_callback
  • I'm using the third-party request package. Link in description.
  • Poking around in the source, it seems to imply that the syntax would be "hostname" rather than "host"? Or you could define proxy as the string "127.0.0.1:8888" rather than as an object?
  • Changing "host" to "hostname" did not help. Can you get it working?
  • Thanks a lot. the setting NODE_TLS_REJECT_UNAUTHORIZED really helps. Without it, https request won't work for me. Just curious, what does this environment variable mean?
  • I believe it allows Node to use self-signed SSL certificates, which would normally be a security risk, but in this case it's what you want :)
  • Did you edit your question or did I get a REAL blackout and missed that part in your code example? LOL
  • Although proxy is implicitly mentioned in the first post, this one solved the problem for me by drawing my attention more explicitly. Thanks @poni.
  • For me, on Windows 10, the first 2 lines did not work. It works without the quotes..