title: HTTPS Request returns getaddrinfo ENOTFOUND
body: <p>I am attempting to make an HTTPS POST request to the <a href="https://petstore.swagger.io/v2/pets" rel="nofollow noreferrer">https://petstore.swagger.io/v2/pets</a> endpoint. Documentation can be found here: <a href="https://petstore.swagger.io/#/" rel="nofollow noreferrer">https://petstore.swagger.io/#/</a>. It works fine using Postman, but when I make the same request, with the same data using Node.js I get the following error:</p>
  <pre><code>Error: getaddrinfo ENOTFOUND petstore.swagger.io/v2
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'petstore.swagger.io/v2'
  }
  </code></pre>
  <p>Here is the complete code:</p>
  <pre><code>import * as https from 'https';
  
  async function main()  {
  
      const data = JSON.stringify({
          name: 'doggie',
          photoUrls: [
              &quot;string&quot;
          ]
      });
  
      const options = {
          hostname: &quot;petstore.swagger.io/v2&quot;,
          path: &quot;/pet&quot;,
          body: data
      }
  
      try {
          let response = await httpRequest(options);
          console.log(response);
      } catch (err) {
          console.log(err);
      }
  }
  
  function httpRequest(options) {
      return new Promise((resolve, reject) =&gt; {
  
          const clientRequest = https.request(options, incomingMessage =&gt; {
  
              // Response object.
              let response = {
                  statusCode: incomingMessage.statusCode,
                  headers: incomingMessage.headers,
                  body: []
              };
  
              // Collect response body data.
              incomingMessage.on('data', chunk =&gt; {
                  response.body.push(chunk);
              });
  
              // Resolve on end.
              incomingMessage.on('end', () =&gt; {
                  if (response.body.length) {
  
                      response.body = response.body.join();
  
                      try {
                          response.body = JSON.parse(response.body);
                      } catch (error) {
                          // Silently fail if response is not JSON.
                      }
                  }
  
                  resolve(response);
              });
          });
          
          // Reject on request error.
          clientRequest.on('error', error =&gt; {
              reject(error);
          });
  
          // Write request body if present.
          if (options.body) {
              clientRequest.write(options.body);
          }
  
          // Close HTTP connection.
          clientRequest.end();
      });
  }
  
  main();
  </code></pre>
  <p>What am I messing up? Thanks!</p>