Friday, 26 May 2017

Send a variable to form parameter in request HTTP POST node js

I'm trying to send an HTTP POST request throw Node js.

Here's my code:

var tentativa = "{ id:'" +  result.rows[i][0] + "', timestamp:'" + result.rows[i][1]+"', application: '"+ applicationName +
              "', type:'Log', source: '" + result.rows[i][2] + "', " + string+ " }";

            request({
              uri: "http://localhost:5000/logs",
              method: "POST",
              form:   tentativa,
              headers: { 'Content-Type' : 'application/x-www-form-urlencoded' }
              }, function(error, response, body) {
                console.log(body);

            }); 

When I send the "tentativa" variable in the form, the request its sent but not saves anything. But when I send the output of the "tentativa" variable it work fine. Shouldn't it be the same?



via Catarina Franco

No comments:

Post a Comment