Answer the question
In order to leave comments, you need to log in
How to authorize a site using fetch.js?
Good evening guys, I almost despaired of doing the right code, help someone please!
I removed the headers from the site and passed them to Headers, passed the parameters from form data to BOdy
utf8:✓
authenticity_token: token
login:[email protected]
password:1q2w3
{"error":"Неверное имя пользователя или пароль","fields":["login","password"]}
const fetch = require('node-fetch');
var server = "http://сайт/login";
myHeaders = {
Cookie: "КУКА",
"Origin": "http://сайт",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "ru,en-US;q=0.8,en;q=0.6,zh;q=0.4,zh-TW;q=0.2,zh-CN;q=0.2",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Accept": "application/json, text/javascript, */*; q=0.01",
"Referer": "http://сайт/login",
"X-Requested-With": "XMLHttpRequest",
"Connection": "keep-alive"
};
var body = JSON.stringify({
utf8: "✓",
authenticity_token: "token",
login: "[email protected]",
password: "1e4r"
});
fetch(server, { method: 'POST', headers: myHeaders, body: body, credentials:'same-origin'})
.then((res) => {
console.log(res);
console.log("___________________________________");
console.log(res.headers);
//return res.json();
})
.catch(function(error) { console.log(error); });
Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]:
{ body:
Gunzip {
_readableState: [ReadableState],
readable: true,
_events: [Object],
_eventsCount: 7,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: true,
_transformState: [Object],
bytesRead: 0,
_handle: [Zlib],
_hadError: false,
_writeState: [Uint32Array],
_outBuffer: <Buffer 20 20 3c 64 69 76 20 63 6c 61 73 73 3d 22 6c 69 67 68 74 62 6f 78 5f 74 69 74 6c 65 22 3e 4c 6f 67 20 69 6e 3c 2f 64 69 76 3e 0a 0a 3c 64 69 76 20 73 ... >,
_outOffset: 0,
_level: -1,
_strategy: 0,
_chunkSize: 16384,
_flushFlag: 2,
_scheduledFlushFlag: 0,
_origFlushFlag: 2,
_finishFlushFlag: 2,
_info: undefined },
disturbed: false,
error: null },
[Symbol(Response internals)]:
{ url: 'https://ask.fm/login',
status: 200,
statusText: 'OK',
headers: Headers { [Symbol(map)]: [Object] } } }
___________________________________
Headers {
[Symbol(map)]:
{ 'content-type': [ 'text/html; charset=utf-8' ],
'transfer-encoding': [ 'chunked' ],
status: [ '200 OK' ],
'cache-control': [ 'max-age=0, private, must-revalidate' ],
etag: [ 'W/"1d0e1cbd9e4830bb83328d62a5cbd13a"' ],
'x-frame-options': [ 'SAMEORIGIN' ],
'x-xss-protection': [ '1; mode=block' ],
'x-content-type-options': [ 'nosniff' ],
date: [ 'Wed, 06 Jun 2018 19:50:27 GMT' ],
'set-cookie':
[ 'locale=en; path=/; expires=Fri, 07 Jun 2019 01:50:27 -0000',
'_m_ask_fm_session=OUR1V3RDMloreEJYTTg4dDJqVDFYL01yZVhkbzJVRDFzZEtYTFozZXM4N2hpaXVZRXIyUFE3NndoNkVHc25uU0ovZy9nRHUyWU9nZEZXc2xNZHI2OXRNL1dwb0hNVFhGNjhWUTh1NE9LSXdmREc3M25JaWl1ZnhNSVBlSDJoY1dZMVVqTDdCWm9UQ1ptWW9CanRYYmlBPT0tLStWTHRCUzl1Ym
VDaGJvS3RvWEVtVmc9PQ%3D%3D--9f2790322cdd7f2da9f04f5a5984f94b17d76ca5; path=/; expires=Sat, 09 Jun 2018 19:50:27 -0000; secure; HttpOnly' ],
server: [ 'Ask.FM Web Service' ],
'content-encoding': [ 'gzip' ],
'strict-transport-security': [ 'max-age=63072000' ] } }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question