A
A
AlexMark2018-12-21 18:58:50
Node.js
AlexMark, 2018-12-21 18:58:50

How to fetch cookies from another site's response using node-fetch?

The bottom line is that I use the node-fetch module all over the place to parse the site.
But it doesn't return the same data to me that I can get using the request module.
Perhaps I have an error in the code that I did not take into account, or is it still better to switch to another module?
request:

var options = { method: 'POST',
  url: 'https://siteurl/login.php',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'multipart/form-data;' },
  formData: 
   { username: 'name',
     password: 'pass',
     autologin: 'on', } };

 request(options, function (error, response, body) {
   if (error) throw new Error(error);

   console.log(response.headers['set-cookie']);
});

node fetch
const form = new FormData();
form.append('username', 'name');
  form.append('password', 'pass');
  form.append('autologin', 'on');
 fetch('https://siteurl/login.php', { method: 'POST',  body:  form})
  .then(response => response.headers.get('set-cookie'));

With the first request, I get all the necessary information for the login, and in the second, there is no longer part of the cookies that are responsible for the login.
I understand that the problem may be in the receiving site, but I send essentially identical requests, don't I?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question