What is the Postman interception mode equivalent in Node.js?

I used to send requests using the Postman Interceptor ( https://chrome.google.com/webstore/detail/postman-interceptor/aicmkgpgakddgnaphhhpliifpcfhicfo?hl=en ). This is how I processed the headers and body of the request:

enter image description here enter image description here

You can try it yourself. You can see, as soon as you turn on the “interception mode”, you get a different answer than “without”.

Now I want to send the same request, but using the "https" module in Node.js.

I executed the following template:

var https = require('https');
var querystring = require('querystring');

var post_data = querystring.stringify({
   hid_last: "SMITH",
   hid_first: "JOHN",
   __RequestVerificationToken: "EiO369xBXRY9sHV/x26RNwlMzWjM9sR/mNlO9p9tor0PcY0j3dRItKH8XeljXmTfFWT0vQ1DYBzlGpLtnBBqEcOB51E9lh6wrEQbtMLUNOXpKKR3RzFqGc9inDP+OBIyD7s9fh9aMAypCHFCNFatUkx666nf7NOMHHKfiJKhfxc=",
   hid_max_rows: 20,
   hid_page: 1,
   hid_SearchType: 'PARTYNAME'
});

// An object of options to indicate where to post to
var post_options = {
   host: 'a836-acris.nyc.gov',
   path: '/DS/DocumentSearch/PartyNameResult',
   method: 'POST',
   headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Origin': 'https://a836-acris.nyc.gov',
      'Referer': "https://a836-acris.nyc.gov/DS/DocumentSearch/PartyName",
      'Upgrade-Insecure-Requests': 1,
      'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
      'Content-Length': Buffer.byteLength(post_data),
      'Cookie': '_ga=GA1.2.1526584332.1483281720; WT_FPC=id=2fb6833e-6ae6-4529-b84a-4a1c61f24978:lv=1483256520738:ss=1483256520738',

   }
};

// Set up the request
var post_req = https.request(post_options, function(res) {
   res.setEncoding('utf8');
   res.on('data', function (chunk) {
       console.log('Response: ' + chunk);
   });
});

// post the data
post_req.write(post_data);
post_req.end();

The only thing missing is the interceptor problem. When I use this code now, I get the same answer that I used to not use the "interceptor" mode in Postman.

, "" "" Postman "https" Node.js?

+4

Source: https://habr.com/ru/post/1665464/


All Articles