title: can use API GET but not API POST
body: <p>Im working on an existing Windows Service project in VS 2013.</p>
  
  <p>I've added a web API Controller class I cant remember now if its a (v2.1) or (v1) controller class....Anyway I've called it SyncPersonnelViaAwsApiController</p>
  
  <p>Im trying to call it from a AWS lambda...so If I call the GET</p>
  
  <pre><code>public string Get(int id)
      {
          return "value";
      }
  </code></pre>
  
  <p>with const req = https.request('<a href="https://actualUrlAddress/api/SyncPersonnelViaAwsApi/Get/4" rel="noreferrer">https://actualUrlAddress/api/SyncPersonnelViaAwsApi/Get/4</a>', (res) => {</p>
  
  <p>I get <code>returned body: undefined"value"</code> which is correct.
   However if I try and call </p>
  
  <pre><code>const req = https.request('https://actualUrlAddress/api/SyncPersonnelViaAwsApi/SapCall', (res) =&gt; {
  </code></pre>
  
  <p>I get <code>returned body: undefined{"Message":"The requested resource does not support http method 'GET'."}</code></p>
  
  <pre><code> //// POST api/&lt;controller&gt;
      public string SapCall([FromBody]string xmlFile)
      {
          string responseMsg = "Failed Import User";
  
          if (!IsNewestVersionOfXMLFile(xmlFile))
          {
              responseMsg = "Not latest version of file, update not performed";
          }
          else
          {
              Business.PersonnelReplicate personnelReplicate = BusinessLogic.SynchronisePersonnel.BuildFromDataContractXml&lt;Business.PersonnelReplicate&gt;(xmlFile);
              bool result = Service.Personnel.SynchroniseCache(personnelReplicate);
  
              if (result)
              {
                  responseMsg = "Success Import Sap Cache User";
              }
          }
  
          return "{\"response\" : \" " + responseMsg + " \" , \"isNewActiveDirectoryUser\" : \" false \"}";
      }
  </code></pre>
  
  <p>Does anyone have any idea why it works for GET and not POST?</p>
  
  <p>As we can hit the get im confident its not the lambda but I have included it just incase</p>
  
  <pre><code>const AWS = require('aws-sdk');
  const https = require('https');
  var s3 = new AWS.S3();
  var un;
  var pw;
  var seralizedXmlFile;
  
  
  let index = function index(event, context, callback) {
  
      // For the purpose of testing I have populated the bucket and key params with objects that already exist in the S3 bucket  
      var params = {
      Bucket: "testbucketthur7thdec",
      Key: "personnelData_50312474_636403151354943757.xml"
  };
  
  
  // Get Object from S3 bucket and add to 'seralizedXmlFile'
  s3.getObject(params, function (data, err) {
      console.log("get object from S3 bucket");
      if (err) {
          // an error occurred
      }
      else
      {
          console.log("data " + data);
          // populate seralizedXmlFile with data from S3 bucket
          let seralizedXmlFile = err.Body.toString('utf-8'); // Use the encoding necessary
          console.log("objectData " + seralizedXmlFile);
      }
  
  });
  
      // set params
      var ssm = new AWS.SSM({ region: 'Usa2' });
      console.log('Instatiated SSM');
      var paramsx = {
          'Names': ['/Sap/ServiceUsername', '/Sap/ServicePassword'],
          'WithDecryption': true
      };
  
  // password and username
      ssm.getParameters(paramsx, function (err, data) {
          console.log('Getting parameter');
          if (err) console.log(err, err.stack); // an error occurred
          else {
              console.log('data: ' + JSON.stringify(data));           // successful response
              console.log('password: ' + data.Parameters[0].Value);
              console.log('username: ' + data.Parameters[1].Value);
              pw = data.Parameters[0].Value;
              un = data.Parameters[1].Value;
          }
  
  
          // request to external api application &amp; remove dependency on ssl
          process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  
          //POST DOES NOT WORK
          const req = https.request('https://actualUrlAddress/api/SyncPersonnelViaAwsApi/SapEaiCall', (res) =&gt; {
          //GET WORKS
         // const req = https.request('https://actualUrlAddress/api/SyncPersonnelViaAwsApi/Get/4', (res) =&gt; {
  
              res.headers + 'Authorization: Basic ' + un + ':' + pw;
              let body = seralizedXmlFile;
              console.log('seralizedXmlFile: ' + seralizedXmlFile); 
              console.log('Status:', res.statusCode);
              console.log('Headers:', JSON.stringify(res.headers));
  
              res.setEncoding('utf8');
              res.on('data', (chunk) =&gt; body += chunk);
              res.on('end', () =&gt; {
                  console.log('Successfully processed HTTPS response');
                  callback(null, body);
                  console.log('returned body:', body);
  
              });
          });
          req.end();
      });
  };
  exports.handler = index;
  </code></pre>
  
  <p><strong>UPDATE</strong>
  Thanks to @Thangadurai post with <a href="https://stackoverflow.com/questions/32636956/aws-lambda-nodejs-post-request-and-asynch-write-read-file">AWS Lambda - NodeJS POST request and asynch write/read file</a></p>
  
  <p>I was able to include a post_options...please see updated lambda</p>
  
  <pre><code>          // An object of options to indicate where to post to
      var post_options = {
          host: 'https://actualUrlAddress',
          port: '80',
          path: '/api/SyncPersonnelViaAwsApi/SapEaiCall',
          method: 'POST',
          headers: {
              'Content-Type': 'application/json',
              'Content-Length': post_data.length
          }
      };
  
   const req = https.request(post_options, (res) =&gt; {
     res.headers + 'Authorization: Basic ' + un + ':' + pw;
              let body = seralizedXmlFile;
              console.log('seralizedXmlFile: ' + seralizedXmlFile); 
              console.log('Status:', res.statusCode);
              console.log('Headers:', JSON.stringify(res.headers));
  
              res.setEncoding('utf8');
              res.on('data', (chunk) =&gt; body += chunk);
              res.on('end', () =&gt; {
                  console.log('Successfully processed HTTPS response');
                  callback(null, body);
                  console.log('returned body:', body);
  
              });
          });
          req.end();
  </code></pre>
  
  <p>It is now flagging as error:</p>
  
  <pre><code>Error: getaddrinfo ENOTFOUND http://actualUrlAddress http://actualUrlAddress.private:80
  </code></pre>
  
  <p>I had this getaggrinfo ENOTFOUND error before, it means it cant find the address....but arnt the hostname and api path correct?</p>
  
  <p>I am trying to reach</p>
  
  <pre><code>const req = https.request('https://actualUrlAddress/api/SyncPersonnelViaAwsApi/SapCall
  </code></pre>
  
  <p>and yes the port is 80</p>
  
  <p>any help would be appreciated
  Ta
  M</p>