title: How can I fake browser POST request with NodeJS?
body: <p>I want to send a POST request to <code>example.com</code> just like browser does. There's a form on <code>example.com</code> that you submit and it gives you the information for the subset you selected.</p>
  
  <p>When I submit it with browser it shows the information. And here are the page headers in Chrome:
  <a href="https://i.stack.imgur.com/Wt09i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wt09i.png" alt="Chrome headers"></a></p>
  
  <p>But when I try to send a request on my own from <code>myserver.com</code> like this:</p>
  
  <pre><code>request.post({
      url: 'http://example.com',
      json : false,
      withCredentials: true,
      headers: {
          //'POST /study/?id=11 HTTP/1.1':'',
          'Host':'example.com',
          'Connection':'keep-alive',
          'Content-Length':'34',
          'Cache-Control':'max-age=0',
          'Origin':'http://example.com',
          'Upgrade-Insecure-Requests':'1',
          'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
          'Content-Type':'application/x-www-form-urlencoded',
          'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
          'Referer':'http://example.com',
          //'Accept-Encoding':'gzip, deflate',
          'Accept-Language':'en-US,en;q=0.8,ru;q=0.6',
          'Cookie':'ssd_num=1m99jeo61eb4srduha9osqr9p2',
          'X-Compress':'null',
      },
      formData: {
          'tmtblTip':'0',
          'showKla':'10%E0',
          'sbShRKl':'1'
      },
      encoding: null
  }, (err, res, data) =&gt; {
      if (err) {
          console.log('Error:', err);
      } else if (res.statusCode !== 200) {
          console.log('Status:', res.statusCode);
      } else {
          // data is already parsed as JSON:
          //let bodyWithCorrectEncoding = iconv.decode(data, 'win1251');
          let bodyWithCorrectEncoding = toUtf(data, 'utf8','win1251');
          console.log(bodyWithCorrectEncoding);
      }
  });
  </code></pre>
  
  <p>When I do this it returns the webpage, but it says <code>There's no such subset</code>.</p>
  
  <p>Can you please tell me what is the difference between these requests (mine and browser)?</p>