N
N
Nikolay372021-07-04 11:00:55
Node.js
Nikolay37, 2021-07-04 11:00:55

How to send a post request to Node.js?

var request = require('request');

request.post({
  url: '*',
  headers: {
    'content-type': 'application/json',
  },
  body: {
    page: 1,
    size: 5,
    color: 7
  }
  function optionalCallback(err, httpResponse, body) {
    console.log(body)
  }
})

When sending this request, I get in response:
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object

I tried to send with body: {'page': 1,'size': 5,'color': 7} , there is absolutely no difference, what is this error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Sanych, 2021-07-04
@Nikolay37

request is deprecated, use node-fetch , everything is simpler there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question