title: Downloading pdf file doesn't work in node js
body: <p>I'm trying to download a pdf file from url but I encountered error :</p>
  <pre><code>Error: connect ECONNREFUSED 127.0.0.1:443
  at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
  Emitted 'error' event on ClientRequest instance at:
      at TLSSocket.socketErrorListener (_http_client.js:426:9)
      at TLSSocket.emit (events.js:310:20)
      at emitErrorNT (internal/streams/destroy.js:92:8)
      at processTicksAndRejections (internal/process/task_queues.js:84:21) {
    errno: 'ECONNREFUSED',
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 443
  }
  </code></pre>
  <p>and here is my code:</p>
  <pre><code>const https = require(&quot;https&quot;);
  const fs = require(&quot;fs&quot;);
  const path = require(&quot;path&quot;);
  
  
  const url = #hidden#
  
  const optionsStart = {
      uri: url,
      method: 'GET',
      encoding: null,
      headers: {
          'Content-type': 'applcation/pdf'
      }
  }
  
  
  const req = https.get(optionsStart, function(res){
      const fileStream = fs.createWriteStream(&quot;Testingpdf123.pdf&quot;);
      res.pipe(fileStream);
  
      fileStream.on(&quot;error&quot;, function(err){
          console.log(&quot;Error writing to the stream.&quot;);
          console.log(err);
      });
  
      fileStream.on(&quot;finish&quot;, () =&gt; {  
          fileStream.close();
          console.log(&quot;Done!&quot;);
      });
  
  });
  </code></pre>
  <p>I tried replacing optionsStart to just url but the file is blank. What's wrong with my code?</p>
  <p>UPDATE:</p>
  <p>I remove the method: 'GET' in optionsStart it creates a pdf file but empty then I check what's inside the file it says</p>
  <pre><code>&lt;meta name=&quot;heading&quot; content=&quot;Access Denied&quot; /&gt;
  </code></pre>