1

I mean, i'm trying to make the most simple upload ever, with the following code:

var http = require('http');

var request = http.request({
  method: 'post',
  host: 'https://www.ws-ti.4bank.com',
  path: '/img/create_file',
  headers: form.getHeaders()
});

form.pipe(request);

request.on('response', function(res) {

  console.log(res.statusCode);
});

The point is, if i make a post like this, what it'll post exacly? Does i need to put at least one header parameter or this create some kind of template? If i need to put at least one parameter, i would put it into the form.getHeaders"()"?

Turnip
  • 35,836
  • 15
  • 89
  • 111
PPNFilms
  • 55
  • 2
  • 7
  • Does this answer your question? [How is an HTTP POST request made in node.js?](https://stackoverflow.com/questions/6158933/how-is-an-http-post-request-made-in-node-js) – O. Jones Feb 03 '20 at 13:14
  • There is a whole mess of request options you must set to do this. – O. Jones Feb 03 '20 at 13:16

1 Answers1

0

Through headers you should send HTTP headers of the request as an object

Example code:

var request = http.request({
  method: 'post',
  host: 'https://www.ws-ti.4bank.com',
  path: '/img/create_file',
  headers: {
    'Accept': 'text/html',
  }
});

full list of the header can be found here

You can send data as JSON with the request as follows:

const data = JSON.stringify({
  text: 'Hello World'
});

request.write(data);
request.end();
Hasan Tareque
  • 1,761
  • 11
  • 21