5

so i have browser(netscape?) cookie like that nscookie or JSON cookie like jsoncookie

How should i pass this into request?

code source:

const
    fs = require('fs'),
    https = require('https'),
    axios = require('axios');

function reqTest()
{

    axios.default.request({
        'url': 'google.com',
        'method': 'post',
        'headers':
            {
                'Cookie': 'cookie1=?; cookie2=?;'
            }
    }
    ).then(res => {
        console.log(res);
    })
}
kanekipos2
  • 53
  • 1
  • 5

1 Answers1

5

Having the withCredentials key enabled (set to 'true') should solve your issue.

Please try this:

const
    fs = require('fs'),
    https = require('https'),
    axios = require('axios');

function reqTest()
{

    axios.default.request({
        'url': 'google.com',
        'method': 'post',
        'headers':
            {
                'Cookie': 'cookie1=?; cookie2=?;'
            },
        'withCredentials': 'true' // ADD THIS LINE
    }
    ).then(res => {
        console.log(res);
    })
}

You can also enable this property for all requests in this instance of axios, changing axios' defaults:

axios.defaults.withCredentials = true;

axios.post(url, body).then(...).catch(...); // withCredentials is automatically enabled

Please report results.

Yitzchak
  • 3,303
  • 3
  • 30
  • 50
tbger99
  • 196
  • 1
  • 4
  • yep, this option is really needed, but i still cant find information about how can i put netscape-format cookie into axios request body – kanekipos2 Feb 06 '22 at 08:32
  • i do not understand how it works at all, i have a login cookie that can auth me into account,like session cookie, and i need to make request with that cookie to get an html doc like im logged into account – kanekipos2 Feb 06 '22 at 08:34