title: Curl JSON Post with node-libcurl
body: <p>I  am using node-libcurl to post a JSON to a URL and receive back a JSON.</p>
  
  <p>I tested the CURL on PHP and it works fine.</p>
  
  <p>The PHP code is the following</p>
  
  <pre><code>$data = array('user' =&gt; $us, 'pwd' =&gt; $cl);
  $data_string = json_encode($data);
  
  $ch = curl_init('http://52.234.214.55:9001/autenticacion/externo');
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      'Content-Type: application/json',
      'Content-Length: ' . strlen($data_string))
  );
  
  $result = curl_exec($ch);
  </code></pre>
  
  <p>Now i want to make it work on a node route that looks like this:</p>
  
  <pre><code>app.post('/login2',function(req,res){
  
    //formato JSON ACHS
    var cvalue = {
        'user': 'user',
        'pwd': 'pass'
      }
  
      var curl = new Curl();
  
      curl.setOpt('URL', 'http://52.234.214.55:9001/autenticacion/externo');
      curl.setOpt('CURLOPT_CUSTOMREQUEST', "POST");
      curl.setOpt('CURLOPT_POSTFIELDS', cvalue);
      curl.setOpt('CURLOPT_RETURNTRANSFER', true);
      curl.setOpt('CURLOPT_HTTPHEADER', array(
          'Content-Type: application/json',
          'Content-Length: ' . strlen(cvalue)));
  
  curl.on('end', function(statusCode, body, headers) {
  
      console.info(statusCode);
      console.info('---');
      console.info(body.length);
      console.info('---');
      console.info(this.getInfo( 'TOTAL_TIME'));
  
      this.close();
  });
  
  curl.on('error', curl.close.bind(curl));
  curl.perform();
  
  })
  </code></pre>
  
  <p>This does not work i get the following error:</p>
  
  <p>Unknown option given. First argument must be the option internal id or the option name. You can use the Curl.option constants.
      at Curl.setOpt (C:\Users\Ingolf\workspace\w2_achs2\node_modules\node-libcurl\lib\Curl.js:980:11)
      at C:\Users\Ingolf\workspace\w2_achs2\index.js:130:10</p>
  
  <p>this points to </p>
  
  <pre><code>curl.setOpt('CURLOPT_CUSTOMREQUEST', "POST");
  </code></pre>
  
  <p>As suggested and found in documentation i changed it to:</p>
  
  <pre><code>curl.setOpt(Curl.option.URL, 'http://52.234.214.55:9001/autenticacion/externo');
  curl.setOpt(Curl.option.CUSTOMREQUEST, "POST");
  curl.setOpt(Curl.option.CURLOPT_POSTFIELDS, cvalue);
  curl.setOpt(Curl.option.CURLOPT_RETURNTRANSFER, true);
  curl.setOpt(Curl.option.CURLOPT_HTTPHEADER, array(
      'Content-Type: application/json',
      'Content-Length: ' . strlen(cvalue)));
  </code></pre>
  
  <p>this gets the error:</p>
  
  <p>Unknown option given. First argument must be the option internal id or the option name. You can use the Curl.option constants.
      at Curl.setOpt (C:\Users\Ingolf\workspace\w2_achs2\node_modules\node-libcurl\lib\Curl.js:980:11)
      at C:\Users\Ingolf\workspace\w2_achs2\index.js:131:10</p>
  
  <p>wich points to </p>
  
  <pre><code>curl.setOpt(Curl.option.CURLOPT_POSTFIELDS, cvalue);
  </code></pre>
  
  <p>thanks for helping.</p>