Search code examples
javascriptnode.jspostmanhttp-status-code-301superagent

Difference between Postman and a simple Http Request with superagent


I was wondering what's the difference between a simple POST request with superagent and a POST request with Postman. Because Im trying to scrap a website, so I made a post request with Postman and everythings work fine, I got the result expected. But when I proceed a POST Http request with superagent, I got a 301 redirect.

There's a way to pass this problem in having the same result as Postman ?

Thanks in advance for your answer.


Solution

  • You should use redirects. Simple example:

    const request = require('superagent');
    const url = 'localhost:3000/example';
    request
    .post(url)
    .send({msg: "hello"})
    .redirects(1) //Add redirect functionality
    .on('redirect', function(res) {
      console.log('Redirected');
    })
    .end(function(err, res){
      console.log(res);
    })